[mcs] switch statement with constant block at first label. Fixes #21805
authorMarek Safar <marek.safar@gmail.com>
Wed, 6 Aug 2014 07:51:52 +0000 (09:51 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 6 Aug 2014 07:52:48 +0000 (09:52 +0200)
mcs/mcs/statement.cs
mcs/tests/test-504.cs
mcs/tests/ver-il-net_4_5.xml

index 444aafebe23934346b7aa8e4daeb69fb37232c85..1e377fe1448afe290fba48329fc26c3e651a47bd 100644 (file)
@@ -5219,14 +5219,16 @@ namespace Mono.CSharp {
 
                                if (sl != null && sl.SectionStart) {
                                        //
-                                       // Section is marked already via constant switch or goto case
+                                       // Section is marked already via goto case
                                        //
                                        if (!sl.IsUnreachable) {
                                                section_rc = new Reachability ();
                                                continue;
                                        }
 
-                                       if (section_rc.IsUnreachable) {
+                                       if (constant_label != null && constant_label != sl)
+                                               section_rc = Reachability.CreateUnreachable ();
+                                       else if (section_rc.IsUnreachable) {
                                                section_rc = new Reachability ();
                                        } else {
                                                if (prev_label != null) {
@@ -5239,9 +5241,6 @@ namespace Mono.CSharp {
                                        }
 
                                        prev_label = sl;
-
-                                       if (constant_label != null && constant_label != sl)
-                                               section_rc = Reachability.CreateUnreachable ();
                                }
 
                                section_rc = s.MarkReachable (section_rc);
@@ -5532,7 +5531,7 @@ namespace Mono.CSharp {
 
                public override void AddEndDefiniteAssignment (FlowAnalysisContext fc)
                {
-                       if (case_default == null)
+                       if (case_default == null && !(new_expr is Constant))
                                return;
 
                        if (end_reachable_das == null)
index c1d1f3210e1bcedc74a08aec478f6ee5f227d97e..d99207e30c182c16e4cddf177e5f167281d28bd7 100644 (file)
@@ -3,6 +3,12 @@
 
 using System;
 
+public enum FooEnum
+{
+       One,
+       Two
+};
+
 class Foo
 {
        public static int y = 1;
@@ -41,4 +47,22 @@ class Foo
 
                return s;
        }
+
+       const FooEnum foo = FooEnum.Two;
+
+       static void Test_3 ()
+       {
+               object obj;
+
+               switch (foo) {
+               case FooEnum.One:
+                       obj = new object ();
+                       break;
+               case FooEnum.Two:
+                       obj = new object ();
+                       break;
+               }
+
+               Console.WriteLine (obj);
+       }
 }
index 5f6c441e5d76052337fa535919ae25153b9ff726..9298139dbbdcf026ac1f275a450e1c29c554bbbf 100644 (file)
       <method name="System.String Test_2()" attrs="150">\r
         <size>7</size>\r
       </method>\r
+      <method name="Void Test_3()" attrs="145">\r
+        <size>20</size>\r
+      </method>\r
     </type>\r
   </test>\r
   <test name="test-505.cs">\r