[mono/mono] dd182612: Variables from diffent parameter block still need to be captures even if async block has no await. Fixes #15719
| Newsgroups | gmane.comp.gnome.mono.patches |
|---|---|
| Message-ID | <0000014203d833dc-588fb98d-a0cf-487d-bcb3-df67d07c689f-000000@email.amazonses.com> |
Branch: refs/heads/master
Home: https://github.com/mono/mono
Compare: https://github.com/mono/mono/compare/5b56dc2ce257...dd1826124a41
Commit: dd1826124a410693a63f3af0f7d173cc840509d8
Author: Marek Safar <[email protected]> (marek-safar)
Date: 2013-10-29 10:51:39 GMT
URL: https://github.com/mono/mono/commit/dd1826124a410693a63f3af0f7d173cc840509d8
Variables from diffent parameter block still need to be captures even if async block has no await. Fixes #15719
Changed paths:
M mcs/mcs/context.cs
M mcs/tests/ver-il-net_4_5.xml
Added paths:
A mcs/tests/test-async-53.cs
Modified: mcs/mcs/context.cs
===================================================================
@@ -516,10 +516,12 @@ public bool MustCaptureVariable (INamedBlockVariable local)
//
// Capture only if this or any of child blocks contain await
- // or it's a parameter
+ // or it's a parameter or we need to access variable from
+ // different parameter block
//
if (CurrentAnonymousMethod is AsyncInitializer)
- return local.IsParameter || local.Block.Explicit.HasAwait || CurrentBlock.Explicit.HasAwait;
+ return local.IsParameter || local.Block.Explicit.HasAwait || CurrentBlock.Explicit.HasAwait ||
+ local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
return local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
}
Added: mcs/tests/test-async-53.cs
===================================================================
@@ -0,0 +1,27 @@
+using System;
+
+class Y
+{
+}
+
+class X
+{
+ public event Action<int, string> E;
+
+ void Foo ()
+ {
+ var nc = new Y ();
+
+ E += async (arg1, arg2) => {
+ nc = null;
+ };
+
+ E (1, "h");
+ }
+
+ public static void Main ()
+ {
+ var x = new X ();
+ x.Foo ();
+ }
+}
\ No newline at end of file
Modified: mcs/tests/ver-il-net_4_5.xml
===================================================================
@@ -60244,6 +60244,46 @@
</method>
</type>
</test>
+ <test name="test-async-53.cs">
+ <type name="Y">
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="X">
+ <method name="Void add_E(System.Action`2[System.Int32,System.String])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void remove_E(System.Action`2[System.Int32,System.String])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void Foo()" attrs="129">
+ <size>54</size>
+ </method>
+ <method name="Void Main()" attrs="150">
+ <size>14</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="X+<Foo>c__AnonStorey1">
+ <method name="Void <>m__0(Int32, System.String)" attrs="131">
+ <size>35</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="X+<Foo>c__AnonStorey1+<Foo>c__async0">
+ <method name="Void MoveNext()" attrs="486">
+ <size>44</size>
+ </method>
+ <method name="Void SetStateMachine(IAsyncStateMachine)" attrs="486">
+ <size>13</size>
+ </method>
+ </type>
+ </test>
<test name="test-cls-00.cs">
<type name="CLSCLass_6">
<method name="Void add_Disposed(Delegate)" attrs="2182">
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches