[mcs] Add null operator propagation to probing expressions. Fixes #31289
authorMarek Safar <marek.safar@gmail.com>
Thu, 25 Jun 2015 07:22:20 +0000 (09:22 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 25 Jun 2015 07:23:13 +0000 (09:23 +0200)
mcs/mcs/expression.cs
mcs/tests/test-null-operator-11.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_5.xml

index 274d1ed0ecca389684964d31666a77a4d080da6c..288a48704608945adee1c955e07cbd896ccbdd31 100644 (file)
@@ -1485,6 +1485,11 @@ namespace Mono.CSharp
                        expr.FlowAnalysis (fc);
                }
 
+               public override bool HasConditionalAccess ()
+               {
+                       return expr.HasConditionalAccess ();
+               }
+
                protected abstract string OperatorName { get; }
 
                protected override void CloneTo (CloneContext clonectx, Expression t)
diff --git a/mcs/tests/test-null-operator-11.cs b/mcs/tests/test-null-operator-11.cs
new file mode 100644 (file)
index 0000000..3f14ebe
--- /dev/null
@@ -0,0 +1,28 @@
+class X
+{
+       public static void Main ()
+       {
+               A a = new A ();
+               var x = (a.b?.c?.d as A)?.b;
+       }
+}
+
+class A
+{
+       public B b { get; set; }
+}
+
+class B
+{
+       public C c { get; set; }
+}
+
+class C
+{
+       public D d { get; set; }
+}
+
+class D : A
+{
+
+}
\ No newline at end of file
index 2de0708289be108feb615798881ac07971938548..8fc5955992d18b9490dc8e4be7545d137f8c6644 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-null-operator-11.cs">
+    <type name="X">
+      <method name="Void Main()" attrs="150">
+        <size>60</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A">
+      <method name="B get_b()" attrs="2182">
+        <size>14</size>
+      </method>
+      <method name="Void set_b(B)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="B">
+      <method name="C get_c()" attrs="2182">
+        <size>14</size>
+      </method>
+      <method name="Void set_c(C)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="D get_d()" attrs="2182">
+        <size>14</size>
+      </method>
+      <method name="Void set_d(D)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D">
+      <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">