[mcs] Always store hidden catch variable when clause contains await
authorMarek Safar <marek.safar@gmail.com>
Fri, 13 Jun 2014 15:34:43 +0000 (17:34 +0200)
committerMarek Safar <marek.safar@gmail.com>
Fri, 13 Jun 2014 15:39:11 +0000 (17:39 +0200)
mcs/mcs/statement.cs
mcs/tests/test-async-65.cs
mcs/tests/ver-il-net_4_5.xml

index bd4cd79e8b5bfd10e8a9e46b9ef7639135306a71..ced42136ea55b696914b03b723aca60c8fae31de 100644 (file)
@@ -6419,17 +6419,17 @@ namespace Mono.CSharp {
                                }
 
                                return;
-                       } else {
-                               if (IsGeneral)
-                                       ec.BeginCatchBlock (ec.BuiltinTypes.Object);
-                               else
-                                       ec.BeginCatchBlock (CatchType);
+                       }
 
-                               if (li != null) {
-                                       EmitCatchVariableStore (ec);
-                               } else {
-                                       ec.Emit (OpCodes.Pop);
-                               }
+                       if (IsGeneral)
+                               ec.BeginCatchBlock (ec.BuiltinTypes.Object);
+                       else
+                               ec.BeginCatchBlock (CatchType);
+
+                       if (li != null) {
+                               EmitCatchVariableStore (ec);
+                       } else {
+                               ec.Emit (OpCodes.Pop);
                        }
 
                        if (!Block.HasAwait)
@@ -6458,7 +6458,7 @@ namespace Mono.CSharp {
                {
                        using (bc.Set (ResolveContext.Options.CatchScope)) {
                                if (type_expr == null) {
-                                       if (CreateExceptionVariable (bc.Module.Compiler.BuiltinTypes.Object) && Filter != null) {
+                                       if (CreateExceptionVariable (bc.Module.Compiler.BuiltinTypes.Object)) {
                                                Expression source = new EmptyExpression (li.Type);
                                                assign = new CompilerAssign (new LocalVariableReference (li, Location.Null), source, Location.Null);
                                                Block.AddScopeStatement (new StatementExpression (assign, Location.Null));
index 0492da89af997a8280bc28e9721d6ab10ac1e01d..396723669153c5caf3ce6efed59f90d868660cdd 100644 (file)
@@ -5,10 +5,10 @@ class C
 {
        static int counter;
 
-       public static async Task TestRethrow ()
+       public static async Task TestRethrow (Exception e)
        {
                try {
-                       throw new ApplicationException ();
+                       throw e;
                } catch (ApplicationException) {
                        Console.WriteLine ("x1a");
                        counter = 1;
@@ -19,22 +19,35 @@ class C
                } catch {
                        counter = 9;
                        await Task.Delay (1);
+                       Console.WriteLine ("ga");
                        throw;
                }
        }
 
        public static int Main ()
        {
+               var ex = new ApplicationException ();
                try {
-                       TestRethrow ().Wait ();
+                       TestRethrow (ex).Wait ();
                } catch (AggregateException e) {
-                       if (!(e.InnerException is ApplicationException))
+                       if (e.InnerException != ex)
                                return 1;
                }
 
                if (counter != 3)
                        return 2;
 
+               var ex2 = new NotSupportedException ();
+               try {
+                       TestRethrow (ex2).Wait ();
+               } catch (AggregateException e) {
+                       if (e.InnerException != ex2)
+                               return 3;
+               }
+
+               if (counter != 9)
+                       return 4;
+
                Console.WriteLine ("ok");
                return 0;
        }
index ce3b065091bdd49b6a7b9fe2939843847cd74881..b9acb70491d8302d92be4ee585cad93374423884 100644 (file)
     </type>\r
     <type name="C+&lt;TestDoubleAwait&gt;c__async1">\r
       <method name="Void MoveNext()" attrs="486">\r
-        <size>411</size>\r
+        <size>419</size>\r
       </method>\r
       <method name="Void SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)" attrs="486">\r
         <size>13</size>\r
   </test>\r
   <test name="test-async-65.cs">\r
     <type name="C">\r
-      <method name="System.Threading.Tasks.Task TestRethrow()" attrs="150">\r
-        <size>33</size>\r
-      </method>\r
       <method name="Int32 Main()" attrs="150">\r
-        <size>86</size>\r
+        <size>161</size>\r
       </method>\r
       <method name="Void .ctor()" attrs="6278">\r
         <size>7</size>\r
     </type>\r
     <type name="C+&lt;TestRethrow&gt;c__async0">\r
       <method name="Void MoveNext()" attrs="486">\r
-        <size>339</size>\r
+        <size>363</size>\r
       </method>\r
       <method name="Void SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)" attrs="486">\r
         <size>13</size>\r
       </method>\r
     </type>\r
+    <type name="C">\r
+      <method name="System.Threading.Tasks.Task TestRethrow(System.Exception)" attrs="150">\r
+        <size>41</size>\r
+      </method>\r
+    </type>\r
   </test>\r
   <test name="test-async-66.cs">\r
     <type name="TestFinally">\r