diff options
author | Marek Safar <marek.safar@gmail.com> | 2016-01-27 18:56:31 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2016-01-27 19:00:24 +0300 |
commit | a8f7af783ea6aef81529b4785f451b44472da51c (patch) | |
tree | 2108e0e9e932f36a63bf3d194c3615d41bedd193 | |
parent | 8aa899c20d808edfca80afff47f91f63141b841a (diff) |
[mcs] Reset null operator barrier in parenthesis expression
-rw-r--r-- | mcs/mcs/ecore.cs | 3 | ||||
-rw-r--r-- | mcs/mcs/expression.cs | 4 | ||||
-rw-r--r-- | mcs/tests/test-null-operator-23.cs | 20 | ||||
-rw-r--r-- | mcs/tests/ver-il-net_4_x.xml | 10 |
4 files changed, 36 insertions, 1 deletions
diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index b74da01e65c..52da19a1b97 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -6537,6 +6537,8 @@ namespace Mono.CSharp { ec.Emit (OpCodes.Ldsfld, spec); } else { + var ca = ec.ConditionalAccess; + if (!prepared) { if (conditional_access_receiver) ec.ConditionalAccess = new ConditionalAccessContext (type, ec.DefineLabel ()); @@ -6562,6 +6564,7 @@ namespace Mono.CSharp { if (conditional_access_receiver) { ec.CloseConditionalAccess (type.IsNullableType && type != spec.MemberType ? type : null); + ec.ConditionalAccess = ca; } } diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index 5a21804888e..e8938153c80 100644 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -111,7 +111,9 @@ namespace Mono.CSharp { Expression res = null; - res = expr.Resolve (rc); + using (rc.With (ResolveContext.Options.DontSetConditionalAccessReceiver, false)) { + res = expr.Resolve (rc); + } var constant = res as Constant; if (constant != null && constant.IsLiteral) { diff --git a/mcs/tests/test-null-operator-23.cs b/mcs/tests/test-null-operator-23.cs new file mode 100644 index 00000000000..558328a6ebf --- /dev/null +++ b/mcs/tests/test-null-operator-23.cs @@ -0,0 +1,20 @@ +using System; + +public class X +{ + string field; + + public static int Main () + { + X x = null; + + try { + var res = (x?.field).ToString()?.Length; + return 1; + } catch (NullReferenceException) { + + } + + return 0; + } +}
\ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 7cda6f85b7d..56be2d26469 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -69704,6 +69704,16 @@ </method> </type> </test> + <test name="test-null-operator-23.cs"> + <type name="X"> + <method name="Int32 Main()" attrs="150"> + <size>77</size> + </method> + <method name="Void .ctor()" attrs="6278"> + <size>7</size> + </method> + </type> + </test> <test name="test-partial-01.cs"> <type name="Foo.Hello"> <method name="Void .ctor()" attrs="6278"> |