Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<None Include="TestCases\ILPretty\ExtensionEncodingV2.il" />
<None Include="testcases\ilpretty\ExtensionEncodingV1.il" />
<None Include="TestCases\ILPretty\GuessAccessors.il" />
<None Include="TestCases\ILPretty\InaccessibleParameterTypes.il" />
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
<None Include="TestCases\ILPretty\Issue3442.il" />
<None Include="TestCases\ILPretty\Issue3344CkFinite.il" />
Expand Down Expand Up @@ -209,6 +210,8 @@
<None Include="TestCases\ILPretty\FSharpUsing_Release.cs" />
<Compile Remove="TestCases\ILPretty\GuessAccessors.cs" />
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
<Compile Remove="TestCases\ILPretty\InaccessibleParameterTypes.cs" />
<None Include="TestCases\ILPretty\InaccessibleParameterTypes.cs" />
<Compile Remove="TestCases\ILPretty\NoAccessorProperties.cs" />
<None Include="TestCases\ILPretty\NoAccessorProperties.cs" />
<Compile Remove="TestCases\ILPretty\Issue1145.cs" />
Expand Down
12 changes: 12 additions & 0 deletions ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public void AllFilesHaveTests()
}
}

[Test]
public async Task AnonymousMethodEdgeCases()
{
await Run();
}

[Test, Ignore("Need to decide how to represent virtual methods without 'newslot' flag")]
public async Task Issue379()
{
Expand Down Expand Up @@ -353,6 +359,12 @@ public async Task GuessAccessors()
await Run();
}

[Test]
public async Task InaccessibleParameterTypes()
{
await Run();
}

[Test]
public async Task EmptyBodies()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
public class AnonymousMethodEdgeCases
{
public Func<int, int> AssignmentIsTheLambdaBody()
{
return (int x) => {
int num;
return num = x;
};
}

public Action<object> UsedParameterWithInvalidName()
{
return (object value) => {
Console.WriteLine(value);
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Hand-written input for two anonymous-method shapes that C# cannot express directly:
// an expression-bodied lambda whose body is the assignment declaring its own local, and
// a parameter whose metadata name is not a valid C# identifier but IS used in the body.
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 4:0:0:0
}
.assembly extern System.Core
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 4:0:0:0
}
.assembly AnonymousMethodEdgeCases
{
.ver 1:0:0:0
}
.module AnonymousMethodEdgeCases.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003
.corflags 0x00000001

.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AnonymousMethodEdgeCases
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
.maxstack 8
ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}

.method public hidebysig instance class [System.Core]System.Func`2<int32, int32> AssignmentIsTheLambdaBody () cil managed
{
.maxstack 8
ldarg.0
ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AnonymousMethodEdgeCases::'<AssignmentIsTheLambdaBody>b__1_0'(int32)
newobj instance void class [System.Core]System.Func`2<int32, int32>::.ctor(object, native int)
ret
}

// return num = x; -- the store's value is the return value, so the local has a store and
// no load, and the decompiled lambda body is the assignment itself.
.method private hidebysig instance int32 '<AssignmentIsTheLambdaBody>b__1_0' (int32 x) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 2
.locals init (
[0] int32 num
)
ldarg.1
dup
stloc.0
ret
}

.method public hidebysig instance class [System.Core]System.Action`1<object> UsedParameterWithInvalidName () cil managed
{
.maxstack 8
ldarg.0
ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.AnonymousMethodEdgeCases::'<UsedParameterWithInvalidName>b__2_0'(object)
newobj instance void class [System.Core]System.Action`1<object>::.ctor(object, native int)
ret
}

// The parameter name '<p0>' is what C# emits for an anonymous method declared without a
// parameter list; used here, so the lambda's parameter list has to name it somehow.
.method private hidebysig instance void '<UsedParameterWithInvalidName>b__2_0' (object '<p0>') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 8
ldarg.1
call void [mscorlib]System.Console::WriteLine(object)
ret
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
public class InaccessibleParameterTypes
{
private class Hidden
{
}

public delegate void Handler(Hidden h);

public static void Register(Action<Hidden> callback)
{
}
}
public class InaccessibleParameterTypesConsumer
{
public InaccessibleParameterTypes.Handler Create()
{
return delegate {
};
}

public void Run()
{
InaccessibleParameterTypes.Register(delegate {
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Anonymous methods whose delegate signature contains a type the use site cannot name.
// IL (unlike C#) permits a public delegate with a less-accessible parameter type, so the
// parameter-list-less "delegate {}" form is the only C# syntax the consumer class below
// could legally have used - the decompiler must not expand it to a lambda parameter list.
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly extern System.Core
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly InaccessibleParameterTypes
{
.ver 1:0:0:0
}
.module InaccessibleParameterTypes.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00020003 // ILONLY 32BITPREFERRED

.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes
extends [mscorlib]System.Object
{
.class nested private auto ansi beforefieldinit Hidden
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
.maxstack 8

ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
}

.class nested public auto ansi sealed Handler
extends [mscorlib]System.MulticastDelegate
{
.method public hidebysig specialname rtspecialname instance void .ctor (object 'object', native int 'method') runtime managed
{
}

.method public hidebysig newslot virtual instance void Invoke (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden h) runtime managed
{
}
}

.method public hidebysig static void Register (class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden> callback) cil managed
{
.maxstack 8

ret
}

.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
.maxstack 8

ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
}

.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer
extends [mscorlib]System.Object
{
// Fields
.field private static class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler '<>f__am$cache0'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden> '<>f__am$cache1'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )

// Methods
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler Create () cil managed
{
.maxstack 8

ldsfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache0'
brtrue.s IL_0016

ldnull
ldftn void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<Create>m__0'(class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden)
newobj instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler::.ctor(object, native int)
stsfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache0'

IL_0016: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Handler ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache0'
ret
}

.method public hidebysig instance void Run () cil managed
{
.maxstack 8

ldsfld class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache1'
brtrue.s IL_0016

ldnull
ldftn void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<Run>m__1'(class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden)
newobj instance void class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden>::.ctor(object, native int)
stsfld class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache1'

IL_0016: ldsfld class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden> ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypesConsumer::'<>f__am$cache1'
call void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes::Register(class [System.Core]System.Action`1<class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden>)
ret
}

.method private hidebysig static void '<Create>m__0' (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden '') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 8

ret
}

.method private hidebysig static void '<Run>m__1' (class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.InaccessibleParameterTypes/Hidden '') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 8

ret
}

.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
.maxstack 8

ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
public class Issue1038<TK, TR> where TR : class, new()
{
public event Action<TK, TR> TestEvent = delegate {
public event Action<TK, TR> TestEvent = (TK A_0, TR A_1) => {
};
}
}
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public static Func<Task<int>> AsyncLambda()

public static Func<Task<int>> AsyncDelegate()
{
return async delegate {
return async () => {
await Task.Delay(10);
return 2;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static Func<ValueTask<int>> AsyncLambda()

public static Func<ValueTask<int>> AsyncDelegate()
{
return async delegate {
return async () => {
await Task.Delay(10);
return 2;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ public async Task<int> DeconstructionAssignmentToCapturedLocals(string file)
{
int a = 0;
int b = 0;
await Task.Run(delegate {
await Task.Run(() => {
(a, b) = GetTuple<int, int>();
});
return a + b;
Expand Down
Loading
Loading