Skip to content

Commit 6f032e2

Browse files
Fix #2515: Auto events are not decompiled correctly, if left untouched.
1 parent 1f92b44 commit 6f032e2

File tree

9 files changed

+635
-0
lines changed

9 files changed

+635
-0
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
<Compile Include="TestCases\Correctness\DynamicTests.cs" />
110110
<Compile Include="TestCases\Correctness\StringConcat.cs" />
111111
<Compile Include="TestCases\Pretty\PatternMatching.cs" />
112+
<None Include="TestCases\Ugly\NoPropertiesAndEvents.Expected.cs" />
113+
<Compile Include="TestCases\Ugly\NoPropertiesAndEvents.cs" />
112114
<None Include="TestCases\Pretty\CovariantReturns.cs" />
113115
<Compile Include="TestCases\VBPretty\VBPropertiesTest.cs" />
114116
<None Include="TestCases\ILPretty\Issue2260SwitchString.cs" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
#if ROSLYN
21+
#if !OPT
22+
using System.Diagnostics;
23+
#endif
24+
using System.Runtime.CompilerServices;
25+
#endif
26+
using System.Threading;
27+
28+
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
29+
{
30+
internal class NoPropertiesAndEvents
31+
{
32+
#if ROSLYN
33+
[CompilerGenerated]
34+
#if !OPT
35+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
36+
#endif
37+
#endif
38+
private EventHandler m_MyEvent;
39+
40+
public event EventHandler MyEvent {
41+
#if ROSLYN
42+
[CompilerGenerated]
43+
#endif
44+
add {
45+
EventHandler eventHandler = this.m_MyEvent;
46+
EventHandler eventHandler2;
47+
do
48+
{
49+
eventHandler2 = eventHandler;
50+
EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
51+
eventHandler = Interlocked.CompareExchange(ref this.m_MyEvent, value2, eventHandler2);
52+
} while ((object)eventHandler != eventHandler2);
53+
}
54+
#if ROSLYN
55+
[CompilerGenerated]
56+
#endif
57+
remove {
58+
EventHandler eventHandler = this.m_MyEvent;
59+
EventHandler eventHandler2;
60+
do
61+
{
62+
eventHandler2 = eventHandler;
63+
EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
64+
eventHandler = Interlocked.CompareExchange(ref this.m_MyEvent, value2, eventHandler2);
65+
} while ((object)eventHandler != eventHandler2);
66+
}
67+
}
68+
}
69+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
21+
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
22+
{
23+
internal class NoPropertiesAndEvents
24+
{
25+
public event EventHandler MyEvent;
26+
}
27+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
3+
4+
5+
// Metadata version: v4.0.30319
6+
.assembly extern mscorlib
7+
{
8+
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
9+
.ver 4:0:0:0
10+
}
11+
.assembly tmp8FA
12+
{
13+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
14+
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
15+
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
16+
.permissionset reqmin
17+
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
18+
.hash algorithm 0x00008004
19+
.ver 0:0:0:0
20+
}
21+
.module tmp8FA.tmp
22+
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
23+
.imagebase 0x10000000
24+
.file alignment 0x00000200
25+
.stackreserve 0x00100000
26+
.subsystem 0x0003 // WINDOWS_CUI
27+
.corflags 0x00000001 // ILONLY
28+
29+
30+
// =============== CLASS MEMBERS DECLARATION ===================
31+
32+
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents
33+
extends [mscorlib]System.Object
34+
{
35+
.field private class [mscorlib]System.EventHandler MyEvent
36+
.method public hidebysig specialname instance void
37+
add_MyEvent(class [mscorlib]System.EventHandler 'value') cil managed
38+
{
39+
// Code size 48 (0x30)
40+
.maxstack 3
41+
.locals init (class [mscorlib]System.EventHandler V_0,
42+
class [mscorlib]System.EventHandler V_1,
43+
class [mscorlib]System.EventHandler V_2,
44+
bool V_3)
45+
IL_0000: ldarg.0
46+
IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
47+
IL_0006: stloc.0
48+
IL_0007: ldloc.0
49+
IL_0008: stloc.1
50+
IL_0009: ldloc.1
51+
IL_000a: ldarg.1
52+
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate,
53+
class [mscorlib]System.Delegate)
54+
IL_0010: castclass [mscorlib]System.EventHandler
55+
IL_0015: stloc.2
56+
IL_0016: ldarg.0
57+
IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
58+
IL_001c: ldloc.2
59+
IL_001d: ldloc.1
60+
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&,
61+
!!0,
62+
!!0)
63+
IL_0023: stloc.0
64+
IL_0024: ldloc.0
65+
IL_0025: ldloc.1
66+
IL_0026: ceq
67+
IL_0028: ldc.i4.0
68+
IL_0029: ceq
69+
IL_002b: stloc.3
70+
IL_002c: ldloc.3
71+
IL_002d: brtrue.s IL_0007
72+
73+
IL_002f: ret
74+
} // end of method NoPropertiesAndEvents::add_MyEvent
75+
76+
.method public hidebysig specialname instance void
77+
remove_MyEvent(class [mscorlib]System.EventHandler 'value') cil managed
78+
{
79+
// Code size 48 (0x30)
80+
.maxstack 3
81+
.locals init (class [mscorlib]System.EventHandler V_0,
82+
class [mscorlib]System.EventHandler V_1,
83+
class [mscorlib]System.EventHandler V_2,
84+
bool V_3)
85+
IL_0000: ldarg.0
86+
IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
87+
IL_0006: stloc.0
88+
IL_0007: ldloc.0
89+
IL_0008: stloc.1
90+
IL_0009: ldloc.1
91+
IL_000a: ldarg.1
92+
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate,
93+
class [mscorlib]System.Delegate)
94+
IL_0010: castclass [mscorlib]System.EventHandler
95+
IL_0015: stloc.2
96+
IL_0016: ldarg.0
97+
IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
98+
IL_001c: ldloc.2
99+
IL_001d: ldloc.1
100+
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&,
101+
!!0,
102+
!!0)
103+
IL_0023: stloc.0
104+
IL_0024: ldloc.0
105+
IL_0025: ldloc.1
106+
IL_0026: ceq
107+
IL_0028: ldc.i4.0
108+
IL_0029: ceq
109+
IL_002b: stloc.3
110+
IL_002c: ldloc.3
111+
IL_002d: brtrue.s IL_0007
112+
113+
IL_002f: ret
114+
} // end of method NoPropertiesAndEvents::remove_MyEvent
115+
116+
.method public hidebysig specialname rtspecialname
117+
instance void .ctor() cil managed
118+
{
119+
// Code size 7 (0x7)
120+
.maxstack 8
121+
IL_0000: ldarg.0
122+
IL_0001: call instance void [mscorlib]System.Object::.ctor()
123+
IL_0006: ret
124+
} // end of method NoPropertiesAndEvents::.ctor
125+
126+
.event [mscorlib]System.EventHandler MyEvent
127+
{
128+
.addon instance void ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::add_MyEvent(class [mscorlib]System.EventHandler)
129+
.removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::remove_MyEvent(class [mscorlib]System.EventHandler)
130+
} // end of event NoPropertiesAndEvents::MyEvent
131+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents
132+
133+
134+
// =============================================================
135+
136+
// *********** DISASSEMBLY COMPLETE ***********************
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
3+
4+
5+
// Metadata version: v4.0.30319
6+
.assembly extern mscorlib
7+
{
8+
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
9+
.ver 4:0:0:0
10+
}
11+
.assembly tmp8FB
12+
{
13+
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
14+
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
15+
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
16+
.permissionset reqmin
17+
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
18+
.hash algorithm 0x00008004
19+
.ver 0:0:0:0
20+
}
21+
.module tmp8FB.tmp
22+
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
23+
.imagebase 0x10000000
24+
.file alignment 0x00000200
25+
.stackreserve 0x00100000
26+
.subsystem 0x0003 // WINDOWS_CUI
27+
.corflags 0x00000001 // ILONLY
28+
29+
30+
// =============== CLASS MEMBERS DECLARATION ===================
31+
32+
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents
33+
extends [mscorlib]System.Object
34+
{
35+
.field private class [mscorlib]System.EventHandler MyEvent
36+
.method public hidebysig specialname instance void
37+
add_MyEvent(class [mscorlib]System.EventHandler 'value') cil managed
38+
{
39+
// Code size 41 (0x29)
40+
.maxstack 3
41+
.locals init (class [mscorlib]System.EventHandler V_0,
42+
class [mscorlib]System.EventHandler V_1,
43+
class [mscorlib]System.EventHandler V_2)
44+
IL_0000: ldarg.0
45+
IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
46+
IL_0006: stloc.0
47+
IL_0007: ldloc.0
48+
IL_0008: stloc.1
49+
IL_0009: ldloc.1
50+
IL_000a: ldarg.1
51+
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate,
52+
class [mscorlib]System.Delegate)
53+
IL_0010: castclass [mscorlib]System.EventHandler
54+
IL_0015: stloc.2
55+
IL_0016: ldarg.0
56+
IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
57+
IL_001c: ldloc.2
58+
IL_001d: ldloc.1
59+
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&,
60+
!!0,
61+
!!0)
62+
IL_0023: stloc.0
63+
IL_0024: ldloc.0
64+
IL_0025: ldloc.1
65+
IL_0026: bne.un.s IL_0007
66+
67+
IL_0028: ret
68+
} // end of method NoPropertiesAndEvents::add_MyEvent
69+
70+
.method public hidebysig specialname instance void
71+
remove_MyEvent(class [mscorlib]System.EventHandler 'value') cil managed
72+
{
73+
// Code size 41 (0x29)
74+
.maxstack 3
75+
.locals init (class [mscorlib]System.EventHandler V_0,
76+
class [mscorlib]System.EventHandler V_1,
77+
class [mscorlib]System.EventHandler V_2)
78+
IL_0000: ldarg.0
79+
IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
80+
IL_0006: stloc.0
81+
IL_0007: ldloc.0
82+
IL_0008: stloc.1
83+
IL_0009: ldloc.1
84+
IL_000a: ldarg.1
85+
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate,
86+
class [mscorlib]System.Delegate)
87+
IL_0010: castclass [mscorlib]System.EventHandler
88+
IL_0015: stloc.2
89+
IL_0016: ldarg.0
90+
IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::MyEvent
91+
IL_001c: ldloc.2
92+
IL_001d: ldloc.1
93+
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&,
94+
!!0,
95+
!!0)
96+
IL_0023: stloc.0
97+
IL_0024: ldloc.0
98+
IL_0025: ldloc.1
99+
IL_0026: bne.un.s IL_0007
100+
101+
IL_0028: ret
102+
} // end of method NoPropertiesAndEvents::remove_MyEvent
103+
104+
.method public hidebysig specialname rtspecialname
105+
instance void .ctor() cil managed
106+
{
107+
// Code size 7 (0x7)
108+
.maxstack 8
109+
IL_0000: ldarg.0
110+
IL_0001: call instance void [mscorlib]System.Object::.ctor()
111+
IL_0006: ret
112+
} // end of method NoPropertiesAndEvents::.ctor
113+
114+
.event [mscorlib]System.EventHandler MyEvent
115+
{
116+
.addon instance void ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::add_MyEvent(class [mscorlib]System.EventHandler)
117+
.removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents::remove_MyEvent(class [mscorlib]System.EventHandler)
118+
} // end of event NoPropertiesAndEvents::MyEvent
119+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoPropertiesAndEvents
120+
121+
122+
// =============================================================
123+
124+
// *********** DISASSEMBLY COMPLETE ***********************

0 commit comments

Comments
 (0)