[mcs] Fixes flow analysis of if statement with constant expression
authorMarek Safar <marek.safar@gmail.com>
Thu, 3 Jul 2014 11:42:38 +0000 (13:42 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 3 Jul 2014 15:50:40 +0000 (17:50 +0200)
mcs/mcs/statement.cs
mcs/tests/test-901.cs [new file with mode: 0644]

index b14430ec912d239fd36d03eea6ecc8733e89c379..91b71ef1074557e627c386f136879c1d209341cf 100644 (file)
@@ -278,6 +278,10 @@ namespace Mono.CSharp {
                        var res = TrueStatement.FlowAnalysis (fc);
 
                        if (FalseStatement == null) {
+                               var c = expr as Constant;
+                               if (c != null && !c.IsDefaultValue)
+                                       return true_returns;
+
                                if (true_returns)
                                        fc.DefiniteAssignment = da_false;
                                else
diff --git a/mcs/tests/test-901.cs b/mcs/tests/test-901.cs
new file mode 100644 (file)
index 0000000..bdd7d07
--- /dev/null
@@ -0,0 +1,23 @@
+using System;
+
+class X
+{
+       public static void Main ()
+       {
+               int i;
+               if (true) {
+                       i = 3;
+               }
+
+               Console.WriteLine (i);
+
+               int i2;
+               if (false) {
+                       throw new ApplicationException ();
+               } else {
+                       i2 = 4;
+               }
+
+               Console.WriteLine (i2);
+       }
+}
\ No newline at end of file