[mcs] Add codegen for null operator on result of awaited instance expression of prope...
authorMarek Safar <marek.safar@gmail.com>
Tue, 21 Feb 2017 10:55:44 +0000 (11:55 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 21 Feb 2017 10:57:44 +0000 (11:57 +0100)
mcs/mcs/codegen.cs
mcs/tests/test-async-90.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index d5ba75c12813af9d07e4b3182134f82cc3e557f9..c580a8a7291562eeeb31b519ece86ec395d146b7 100644 (file)
@@ -1070,7 +1070,10 @@ namespace Mono.CSharp
                                        var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));
 
                                        if (Arguments == null) {
                                        var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));
 
                                        if (Arguments == null) {
-                                               ie.EmitLoad (ec, true);
+                                               if (ConditionalAccess)
+                                                       ie.Emit (ec, true);
+                                               else
+                                                       ie.EmitLoad (ec, true);
                                        }
                                } else if (!InstanceExpressionOnStack) {
                                        var ie = new InstanceEmitter (InstanceExpression, IsAddressCall (InstanceExpression, call_op, method.DeclaringType));
                                        }
                                } else if (!InstanceExpressionOnStack) {
                                        var ie = new InstanceEmitter (InstanceExpression, IsAddressCall (InstanceExpression, call_op, method.DeclaringType));
diff --git a/mcs/tests/test-async-90.cs b/mcs/tests/test-async-90.cs
new file mode 100644 (file)
index 0000000..8b1adc6
--- /dev/null
@@ -0,0 +1,35 @@
+using System.Threading.Tasks;
+
+static class Y
+{
+    public static string ExCall (this X x)
+    {
+        return null;
+    }
+}
+
+class X
+{
+    static X Test (object o)
+    {
+        return null;
+    }
+
+    X Prop { get; set;}
+
+    X Call ()
+    {
+        return null;
+    }
+
+    public static void Main ()
+    {
+        var x = new X ();
+        x.Test ().Wait ();
+    }
+
+    async Task Test ()
+    {
+        var x = X.Test (await Task.FromResult (1))?.Prop?.ExCall ();
+    }
+}
\ No newline at end of file
index 294239f325b5e3c2abaedb5fe3f4210d042d2458..97e730296b78af13ec46e19687712f5626fda735 100644 (file)
       </method>
     </type>
   </test>
       </method>
     </type>
   </test>
+  <test name="test-async-90.cs">
+    <type name="Y">
+      <method name="System.String ExCall(X)" attrs="150">
+        <size>10</size>
+      </method>
+    </type>
+    <type name="X">
+      <method name="X Test(System.Object)" attrs="145">
+        <size>10</size>
+      </method>
+      <method name="X get_Prop()" attrs="2177">
+        <size>14</size>
+      </method>
+      <method name="Void set_Prop(X)" attrs="2177">
+        <size>8</size>
+      </method>
+      <method name="X Call()" attrs="129">
+        <size>10</size>
+      </method>
+      <method name="Void Main()" attrs="150">
+        <size>19</size>
+      </method>
+      <method name="System.Threading.Tasks.Task Test()" attrs="129">
+        <size>33</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="X+&lt;Test&gt;c__async0">
+      <method name="Void MoveNext()" attrs="486">
+        <size>290</size>
+      </method>
+      <method name="Void SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)" attrs="486">
+        <size>13</size>
+      </method>
+    </type>
+  </test>
   <test name="test-cls-00.cs">
     <type name="CLSCLass_6">
       <method name="Void add_Disposed(Delegate)" attrs="2182">
   <test name="test-cls-00.cs">
     <type name="CLSCLass_6">
       <method name="Void add_Disposed(Delegate)" attrs="2182">