[mcs] Resolve nullable expression before unwrapping. Fixes #32054
authorMarek Safar <marek.safar@gmail.com>
Mon, 20 Jul 2015 12:07:20 +0000 (14:07 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 20 Jul 2015 12:10:31 +0000 (14:10 +0200)
mcs/mcs/expression.cs
mcs/tests/test-null-operator-12.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 6397f3c8bbf55fab827b9965c21c8642461e5c76..b958df38305b7dd65047b6d3f16aa94dfb0e076c 100644 (file)
@@ -9724,7 +9724,7 @@ namespace Mono.CSharp
                                }
 
                                if (expr_type.IsNullableType) {
-                                       expr = Nullable.Unwrap.Create (expr, true).Resolve (rc);
+                                       expr = Nullable.Unwrap.Create (expr.Resolve (rc), true);
                                        expr_type = expr.Type;
                                }
                        }
diff --git a/mcs/tests/test-null-operator-12.cs b/mcs/tests/test-null-operator-12.cs
new file mode 100644 (file)
index 0000000..71fa664
--- /dev/null
@@ -0,0 +1,14 @@
+class Test
+{
+       int? _state;
+       public bool Working () => _state?.ToString () != "";
+
+       public static int Main ()
+       {
+               var t = new Test ();
+               if (!t.Working ())
+                       return 1;
+
+               return 0;
+       }
+}
index 3cbecba48db3e6f60863c7a026472ec86378cfda..37c936b86d26a970e19a903217d41536dc9d5c18 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-null-operator-12.cs">
+    <type name="Test">
+      <method name="Boolean Working()" attrs="134">
+        <size>61</size>
+      </method>
+      <method name="Int32 Main()" attrs="150">
+        <size>34</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">