FinallyBlock = 1 << 14,
CatchBlock = 1 << 15,
Iterator = 1 << 20,
- NoFlowAnalysis = 1 << 21
+ NoFlowAnalysis = 1 << 21,
+ InitializationEmitted = 1 << 22
}
public Block Parent;
DoEmit (ec);
}
- public void EmitScopeInitializers (EmitContext ec)
+ protected void EmitScopeInitializers (EmitContext ec)
{
foreach (Statement s in scope_initializers)
s.Emit (ec);
-
- scope_initializers = null;
}
protected override bool DoFlowAnalysis (FlowAnalysisContext fc)
return am_storey;
}
- public override void Emit (EmitContext ec)
+ public void EmitScopeInitialization (EmitContext ec)
{
+ if ((flags & Flags.InitializationEmitted) != 0)
+ return;
+
if (am_storey != null) {
DefineStoreyContainer (ec, am_storey);
am_storey.EmitStoreyInstantiation (ec, this);
if (scope_initializers != null)
EmitScopeInitializers (ec);
+ flags |= Flags.InitializationEmitted;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ EmitScopeInitialization (ec);
+
if (ec.EmitAccurateDebugInfo && !IsCompilerGenerated && ec.Mark (StartLocation)) {
ec.Emit (OpCodes.Nop);
}
EmitCatchVariableStore (ec);
if (Block.HasAwait) {
- Block.EmitScopeInitializers (ec);
+ Block.EmitScopeInitialization (ec);
} else {
Block.Emit (ec);
}
--- /dev/null
+using System;
+using System.Threading.Tasks;
+
+class Test
+{
+ static bool Verify (Func<bool> f)
+ {
+ return f ();
+ }
+
+ static async Task<int> TestCapturedException (Exception e)
+ {
+ try {
+ if (e != null)
+ throw e;
+ } catch (Exception ex) if (Verify (() => ex.Message == "foo")) {
+ await Task.Yield ();
+ Console.WriteLine (ex);
+ return 1;
+ } catch (Exception ex) if (Verify (() => ex.Message != null)) {
+ await Task.Yield ();
+ Console.WriteLine (ex);
+ return 2;
+ }
+
+ return 3;
+ }
+
+ public static int Main()
+ {
+ if (TestCapturedException (null).Result != 3)
+ return 1;
+
+ var ex = new ApplicationException ();
+ if (TestCapturedException (ex).Result != 2)
+ return 2;
+
+ return 0;
+ }
+}
\ No newline at end of file
</method>\r
</type>\r
</test>\r
+ <test name="test-ex-filter-05.cs">\r
+ <type name="Test">\r
+ <method name="Boolean Verify(System.Func`1[System.Boolean])" attrs="145">\r
+ <size>15</size>\r
+ </method>\r
+ <method name="System.Threading.Tasks.Task`1[System.Int32] TestCapturedException(System.Exception)" attrs="145">\r
+ <size>41</size>\r
+ </method>\r
+ <method name="Int32 Main()" attrs="150">\r
+ <size>64</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="Test+<TestCapturedException>c__async0">\r
+ <method name="Void MoveNext()" attrs="486">\r
+ <size>491</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="Test+<TestCapturedException>c__async0+<TestCapturedException>c__AnonStorey1">\r
+ <method name="Boolean <>m__0()" attrs="131">\r
+ <size>29</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="Test+<TestCapturedException>c__async0+<TestCapturedException>c__AnonStorey2">\r
+ <method name="Boolean <>m__0()" attrs="131">\r
+ <size>25</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="test-externalias-01.cs">\r
<type name="Test">\r
<method name="Int32 Main()" attrs="150">\r