diff options
author | Marek Safar <marek.safar@gmail.com> | 2013-06-26 16:42:24 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2013-06-26 16:43:34 +0400 |
commit | fcb255425ab576118b5c303568eda164c50da095 (patch) | |
tree | 9a07015bbffc1d3e4afb2178a4980bb9d950dcfb /mcs | |
parent | 53baacbe8476f7320524c78cbad353241de169a5 (diff) |
Fix order of capturing of this inside switch statement. Fixes #12544
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/mcs/statement.cs | 23 | ||||
-rw-r--r-- | mcs/tests/test-anon-171.cs | 52 | ||||
-rw-r--r-- | mcs/tests/test-debug-11-ref.xml | 8 | ||||
-rw-r--r-- | mcs/tests/ver-il-net_4_5.xml | 49 |
4 files changed, 120 insertions, 12 deletions
diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs index ab0b2d7bbd3..b36393fa161 100644 --- a/mcs/mcs/statement.cs +++ b/mcs/mcs/statement.cs @@ -2243,6 +2243,11 @@ namespace Mono.CSharp { scope_initializers.Add (s); } } + + public void InsertStatement (int index, Statement s) + { + statements.Insert (index, s); + } public void AddStatement (Statement s) { @@ -4185,10 +4190,10 @@ namespace Mono.CSharp { } // - // Needed to emit anonymous storey initialization before + // Anonymous storey initialization has to happen before // any generated switch dispatch // - block.AddScopeStatement (new DispatchStatement (this)); + block.InsertStatement (0, new DispatchStatement (this)); return true; } @@ -4415,12 +4420,6 @@ namespace Mono.CSharp { return; } - // - // Mark sequence point explicitly to switch - // - ec.Mark (block.StartLocation); - block.IsCompilerGenerated = true; - if (string_dictionary != null) { DoEmitStringSwitch (ec); } else if (case_labels.Count < 4 || string_labels != null) { @@ -4456,6 +4455,14 @@ namespace Mono.CSharp { } else if (new_expr != value) { value.EmitAssign (ec, new_expr, false, false); } + + + // + // Next statement is compiler generated we don't need extra + // nop when we can use the statement for sequence point + // + ec.Mark (block.StartLocation); + block.IsCompilerGenerated = true; } block.Emit (ec); diff --git a/mcs/tests/test-anon-171.cs b/mcs/tests/test-anon-171.cs new file mode 100644 index 00000000000..ff084d41e8d --- /dev/null +++ b/mcs/tests/test-anon-171.cs @@ -0,0 +1,52 @@ +using System; + +namespace TestAnonSwitch +{ + public class MyClass + { + public event EventHandler<EventArgs> FirstEvent; + public event EventHandler<EventArgs> SecondEvent; + + public void Trigger () + { + if (FirstEvent != null) + FirstEvent (this, EventArgs.Empty); + } + } + + public class Tester + { + MyClass myobj; + + public void Test () + { + myobj = new MyClass (); + var something = "key"; + + switch (something) { + case "key": + myobj.FirstEvent += (sender, e) => { + Console.WriteLine ("FirstEvent: {0}", myobj); + }; + break; + case "somethingelse": + bool? woot = null; + myobj.SecondEvent += (sender, e) => { + Console.WriteLine ("woot {0}", woot); + }; + break; + } + + myobj.Trigger (); + } + } + + class MainClass + { + public static void Main () + { + var tester = new Tester (); + tester.Test (); + } + } +} diff --git a/mcs/tests/test-debug-11-ref.xml b/mcs/tests/test-debug-11-ref.xml index 5d0b5d1f216..e524e16c296 100644 --- a/mcs/tests/test-debug-11-ref.xml +++ b/mcs/tests/test-debug-11-ref.xml @@ -142,7 +142,7 @@ </sequencepoints> <locals /> <scopes> - <entry index="0" start="0x22" end="0x3c" /> + <entry index="0" start="0x1" end="0x3c" /> <entry index="1" start="0x28" end="0x2d" /> </scopes> </method> @@ -159,7 +159,7 @@ </sequencepoints> <locals /> <scopes> - <entry index="0" start="0x28" end="0x38" /> + <entry index="0" start="0x15" end="0x38" /> <entry index="1" start="0x2e" end="0x33" /> </scopes> </method> @@ -178,7 +178,7 @@ </sequencepoints> <locals /> <scopes> - <entry index="0" start="0xb3" end="0xd2" /> + <entry index="0" start="0x1" end="0xd2" /> <entry index="1" start="0xb9" end="0xbe" /> </scopes> </method> @@ -193,7 +193,7 @@ </sequencepoints> <locals /> <scopes> - <entry index="0" start="0x2c" end="0x3b" /> + <entry index="0" start="0x1" end="0x3b" /> </scopes> </method> <method token="0x600000f"> diff --git a/mcs/tests/ver-il-net_4_5.xml b/mcs/tests/ver-il-net_4_5.xml index ab87701f657..fbbd9fa1239 100644 --- a/mcs/tests/ver-il-net_4_5.xml +++ b/mcs/tests/ver-il-net_4_5.xml @@ -51373,6 +51373,55 @@ </method>
</type>
</test>
+ <test name="test-anon-171.cs">
+ <type name="TestAnonSwitch.MyClass">
+ <method name="Void add_FirstEvent(System.EventHandler`1[System.EventArgs])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void remove_FirstEvent(System.EventHandler`1[System.EventArgs])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void add_SecondEvent(System.EventHandler`1[System.EventArgs])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void remove_SecondEvent(System.EventHandler`1[System.EventArgs])" attrs="2182">
+ <size>42</size>
+ </method>
+ <method name="Void Trigger()" attrs="134">
+ <size>30</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="TestAnonSwitch.Tester">
+ <method name="Void Test()" attrs="134">
+ <size>157</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="TestAnonSwitch.MainClass">
+ <method name="Void Main()" attrs="150">
+ <size>14</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="TestAnonSwitch.Tester+<Test>c__AnonStorey0">
+ <method name="Void <>m__0(System.Object, System.EventArgs)" attrs="131">
+ <size>23</size>
+ </method>
+ <method name="Void <>m__1(System.Object, System.EventArgs)" attrs="131">
+ <size>23</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ </test>
<test name="test-anon-18.cs">
<type name="A">
<method name="Void Invoke()" attrs="454">
|