[mcs] Flow analysis on reduced expressions need to run on original expression
authorMarek Safar <marek.safar@gmail.com>
Fri, 4 Aug 2017 11:30:06 +0000 (13:30 +0200)
committerMarek Safar <marek.safar@gmail.com>
Fri, 4 Aug 2017 11:30:06 +0000 (13:30 +0200)
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/tests/test-pattern-08.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index d15fbe5e34f6e9592987a466ff17580e9a95fbb9..7704e72b168738451687821fde3c4ddd8b26a7d9 100644 (file)
@@ -2429,7 +2429,12 @@ namespace Mono.CSharp {
 
                public override void FlowAnalysis (FlowAnalysisContext fc)
                {
-                       expr.FlowAnalysis (fc);
+                       orig_expr.FlowAnalysis (fc);
+               }
+
+               public override void FlowAnalysisConditional (FlowAnalysisContext fc)
+               {
+                       orig_expr.FlowAnalysisConditional (fc);
                }
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
index b9f47b5a361054a9b3675508668144a484c51de8..f94bc4239202e68cce2e8505efcf2d0fa6d1d150 100644 (file)
@@ -1709,7 +1709,7 @@ namespace Mono.CSharp
                                }
 
                                //
-                               // It's ok to have variable builder create out of order. It simplified emit
+                               // It's ok to have variable builder created out of order. It simplifies emit
                                // of statements like while (condition) { }
                                //
                                if (!Variable.Created)
diff --git a/mcs/tests/test-pattern-08.cs b/mcs/tests/test-pattern-08.cs
new file mode 100644 (file)
index 0000000..22b7621
--- /dev/null
@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+
+class Expr
+{
+       public int Field;
+       public Expr Next;
+}
+
+static class X
+{
+       public static IEnumerable<int> Test (this Expr expr)
+       {
+               var exprCur = expr;
+               while (exprCur != null)
+               {
+                       if (exprCur is Expr list)
+                       {
+                               yield return list.Field;
+                               exprCur = list.Next;
+                       }
+                       else
+                       {
+                               yield return 2;
+                               yield break;
+                       }
+               }
+       }
+
+       public static void Main ()
+       {
+       }
+}
\ No newline at end of file
index d570269b1111114ffb12dbd627168c99c644e409..aec54869c331e5d3afba0675a3599cf8544715ac 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-pattern-08.cs">
+    <type name="Expr">
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="X">
+      <method name="System.Collections.Generic.IEnumerable`1[System.Int32] Test(Expr)" attrs="150">
+        <size>30</size>
+      </method>
+      <method name="Void Main()" attrs="150">
+        <size>2</size>
+      </method>
+    </type>
+    <type name="X+&lt;Test&gt;c__Iterator0">
+      <method name="Boolean MoveNext()" attrs="486">
+        <size>184</size>
+      </method>
+      <method name="Int32 System.Collections.Generic.IEnumerator&lt;int&gt;.get_Current()" attrs="2529">
+        <size>14</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()" attrs="2529">
+        <size>19</size>
+      </method>
+      <method name="Void Dispose()" attrs="486">
+        <size>15</size>
+      </method>
+      <method name="Void Reset()" attrs="486">
+        <size>6</size>
+      </method>
+      <method name="System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()" attrs="481">
+        <size>14</size>
+      </method>
+      <method name="System.Collections.Generic.IEnumerator`1[System.Int32] System.Collections.Generic.IEnumerable&lt;int&gt;.GetEnumerator()" attrs="481">
+        <size>40</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-pragma-unrecognized.cs">
     <type name="C">
       <method name="Void Main()" attrs="150">