Skip to content

Commit 7f024de

Browse files
committed
Don't include generic constraints in generated explicit overrides
1 parent d2d76ec commit 7f024de

File tree

7 files changed

+126
-2
lines changed

7 files changed

+126
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
9494
<None Include="TestCases\ILPretty\GuessAccessors.il" />
9595
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
96+
<None Include="TestCases\ILPretty\Issue3442.il" />
9697
<None Include="TestCases\ILPretty\MonoFixed.il" />
9798
<None Include="TestCases\ILPretty\UnknownTypes.cs" />
9899
<None Include="TestCases\ILPretty\UnknownTypes.il" />
@@ -131,9 +132,11 @@
131132
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
132133
<Compile Include="TestAssemblyResolver.cs" />
133134
<Compile Include="TestCases\ILPretty\Issue3421.cs" />
135+
<Compile Include="TestCases\ILPretty\Issue3442.cs" />
134136
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
135137
<Compile Include="TestCases\Pretty\Comparisons.cs" />
136138
<Compile Include="TestCases\Pretty\Issue3439.cs" />
139+
<Compile Include="TestCases\Pretty\Issue3442.cs" />
137140
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
138141
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
139142
<Compile Include="TestCases\VBPretty\VBNonGenericForEach.cs" />

ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ public async Task Issue3421()
213213
await Run();
214214
}
215215

216+
[Test]
217+
public async Task Issue3442()
218+
{
219+
await Run();
220+
}
221+
216222
[Test]
217223
public async Task Issue2260SwitchString()
218224
{

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ public async Task Issue3439([ValueSource(nameof(defaultOptions))] CompilerOption
610610
await RunForLibrary(cscOptions: cscOptions);
611611
}
612612

613+
[Test]
614+
public async Task Issue3442([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
615+
{
616+
await RunForLibrary(cscOptions: cscOptions);
617+
}
618+
613619
[Test]
614620
public async Task AssemblyCustomAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
615621
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442
2+
{
3+
public class Class : Interface
4+
{
5+
private void M<T>() where T : Interface
6+
{
7+
}
8+
9+
void Interface.M<T>()
10+
{
11+
//ILSpy generated this explicit interface implementation from .override directive in M
12+
this.M<T>();
13+
}
14+
}
15+
public interface Interface
16+
{
17+
void M<T>() where T : Interface;
18+
}
19+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.assembly extern System.Runtime
2+
{
3+
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
4+
.ver 4:0:0:0
5+
}
6+
7+
.assembly Issue3442
8+
{
9+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
10+
01 00 08 00 00 00 00 00
11+
)
12+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
13+
01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78
14+
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
15+
)
16+
.custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
17+
01 00 02 00 00 00 00 00
18+
)
19+
.permissionset reqmin = (
20+
2e 01 80 8a 53 79 73 74 65 6d 2e 53 65 63 75 72
21+
69 74 79 2e 50 65 72 6d 69 73 73 69 6f 6e 73 2e
22+
53 65 63 75 72 69 74 79 50 65 72 6d 69 73 73 69
23+
6f 6e 41 74 74 72 69 62 75 74 65 2c 20 53 79 73
24+
74 65 6d 2e 52 75 6e 74 69 6d 65 2c 20 56 65 72
25+
73 69 6f 6e 3d 39 2e 30 2e 30 2e 30 2c 20 43 75
26+
6c 74 75 72 65 3d 6e 65 75 74 72 61 6c 2c 20 50
27+
75 62 6c 69 63 4b 65 79 54 6f 6b 65 6e 3d 62 30
28+
33 66 35 66 37 66 31 31 64 35 30 61 33 61 15 01
29+
54 02 10 53 6b 69 70 56 65 72 69 66 69 63 61 74
30+
69 6f 6e 01
31+
)
32+
.hash algorithm 0x00008004 // SHA1
33+
.ver 0:0:0:0
34+
}
35+
36+
.class private auto ansi '<Module>'
37+
{
38+
} // end of class <Module>
39+
40+
.class interface public auto ansi abstract beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface
41+
{
42+
// Methods
43+
.method public hidebysig newslot abstract virtual
44+
instance void M<(ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface) T> () cil managed
45+
{
46+
} // end of method Interface::M
47+
48+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface
49+
50+
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Class
51+
extends [System.Runtime]System.Object
52+
implements ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface
53+
{
54+
// Methods
55+
.method private final hidebysig newslot virtual
56+
instance void M<(ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface) T> () cil managed
57+
{
58+
.override method instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Interface::M()
59+
// Method begins at RVA 0x2050
60+
// Code size 1 (0x1)
61+
.maxstack 8
62+
63+
IL_0000: ret
64+
} // end of method Class::M
65+
66+
.method public hidebysig specialname rtspecialname
67+
instance void .ctor () cil managed
68+
{
69+
// Method begins at RVA 0x2052
70+
// Code size 7 (0x7)
71+
.maxstack 8
72+
73+
IL_0000: ldarg.0
74+
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
75+
IL_0006: ret
76+
} // end of method Class::.ctor
77+
78+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3442.Class
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue3442
2+
{
3+
public class Class : Interface
4+
{
5+
void Interface.M<T>()
6+
{
7+
}
8+
}
9+
public interface Interface
10+
{
11+
void M<T>() where T : Interface;
12+
}
13+
}

ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,7 @@ IEnumerable<EntityDeclaration> AddInterfaceImplHelpers(
11671167
methodDecl.TypeParameters.AddRange(memberDecl.GetChildrenByRole(Roles.TypeParameter)
11681168
.Select(n => (TypeParameterDeclaration)n.Clone()));
11691169
methodDecl.Parameters.AddRange(memberDecl.GetChildrenByRole(Roles.Parameter).Select(n => n.Clone()));
1170-
methodDecl.Constraints.AddRange(memberDecl.GetChildrenByRole(Roles.Constraint)
1171-
.Select(n => (Constraint)n.Clone()));
1170+
// Constraints are not copied because explicit interface implementations cannot have constraints. CS0460
11721171

11731172
methodDecl.Body = new BlockStatement();
11741173
methodDecl.Body.AddChild(new Comment(

0 commit comments

Comments
 (0)