From daa48fbd3a90a7b06eed45e5e6f5c3381fd05248 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 10 Mar 2018 11:15:53 +0100 Subject: [PATCH] #1080: Add test case --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../TestCases/Pretty/Issue1080.cs | 54 ++++++++ .../TestCases/Pretty/Issue1080.opt.roslyn.il | 115 ++++++++++++++++ .../TestCases/Pretty/Issue1080.roslyn.il | 125 ++++++++++++++++++ .../CSharp/CSharpDecompiler.cs | 1 - ILSpy/Properties/launchSettings.json | 2 +- 7 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 14c054a6d..358621572 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -65,6 +65,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 898d27b8e..356c6aa5c 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -273,6 +273,12 @@ namespace ICSharpCode.Decompiler.Tests RunForLibrary(cscOptions: cscOptions); } + [Test] + public void Issue1080([ValueSource(nameof(roslynOnlyOptions))] CSharpCompilerOptions cscOptions) + { + RunForLibrary(cscOptions: cscOptions); + } + void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CSharpCompilerOptions cscOptions = CSharpCompilerOptions.None, DecompilerSettings decompilerSettings = null) { Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CSharpCompilerOptions.Library, decompilerSettings); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs new file mode 100644 index 000000000..4a498204a --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.cs @@ -0,0 +1,54 @@ +using ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA; +using ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB; +using ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080 +{ + internal static class ExtensionsTest + { + private static void Dummy(ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 intf) + { + } + + private static void Test(object obj) + { + ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 type = obj as ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2; + if (type != null) { + ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions.Extension(type); + } + } + } +} +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB +{ + internal interface Type2 : Type1 + { + } +} +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA +{ + internal interface Type2 : ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2, Type1 + { + } +} +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC +{ + internal static class Extensions + { + public static void Extension(this Type1 obj) + { + } + } +} +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB +{ + internal interface Type1 + { + } + internal static class Extensions + { + public static void Extension(this Type1 obj) + { + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.opt.roslyn.il new file mode 100644 index 000000000..ed9508dcd --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.opt.roslyn.il @@ -0,0 +1,115 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Issue1080 +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Issue1080.dll +// MVID: {4B5AAFB9-5929-4193-B624-4F81D8D3C1BB} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x038A0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.ExtensionsTest + extends [mscorlib]System.Object +{ + .method private hidebysig static void Dummy(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 intf) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method ExtensionsTest::Dummy + + .method private hidebysig static void Test(object obj) cil managed + { + // Code size 17 (0x11) + .maxstack 1 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 V_0) + IL_0000: ldarg.0 + IL_0001: isinst ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0010 + + IL_000a: ldloc.0 + IL_000b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions::Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1) + IL_0010: ret + } // end of method ExtensionsTest::Test + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.ExtensionsTest + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 obj) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Extensions::Extension + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2, + ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 + implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Extensions + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 obj) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Extensions::Extension + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Extensions + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.roslyn.il new file mode 100644 index 000000000..86208afb7 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue1080.roslyn.il @@ -0,0 +1,125 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Issue1080 +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .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 + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Issue1080.dll +// MVID: {C55AD4DD-F921-48E6-8863-FBA5C2E3280E} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x04C30000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.ExtensionsTest + extends [mscorlib]System.Object +{ + .method private hidebysig static void Dummy(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 intf) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method ExtensionsTest::Dummy + + .method private hidebysig static void Test(object obj) cil managed + { + // Code size 24 (0x18) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: isinst ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldnull + IL_000a: cgt.un + IL_000c: stloc.1 + IL_000d: ldloc.1 + IL_000e: brfalse.s IL_0017 + + IL_0010: ldloc.0 + IL_0011: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions::Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1) + IL_0016: nop + IL_0017: ret + } // end of method ExtensionsTest::Test + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.ExtensionsTest + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 obj) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Extensions::Extension + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceC.Extensions + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2, + ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.Type2 + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 + +.class interface private abstract auto ansi ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 + implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 +{ +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type2 + +.class private abstract auto ansi sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Extensions + extends [mscorlib]System.Object +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig static void Extension(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Type1 obj) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Extensions::Extension + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Issue1080.SpaceA.SpaceB.Extensions + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 193df6ba6..bfc48a27e 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -638,7 +638,6 @@ namespace ICSharpCode.Decompiler.CSharp public static void CollectNamespacesForDecompilation(IEnumerable memberDefinitions, HashSet namespaces) { - var visitedItems = new HashSet(); foreach (var def in memberDefinitions) { switch (def) { case TypeDefinition typeDef: diff --git a/ILSpy/Properties/launchSettings.json b/ILSpy/Properties/launchSettings.json index 9456feabf..14017179c 100644 --- a/ILSpy/Properties/launchSettings.json +++ b/ILSpy/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "ILSpy": { "commandName": "Executable", - "executablePath": "$(OutDir)$(AssemblyName)$(TargetExt)", + "executablePath": "C:\\Users\\Siegfried\\Projects\\ILSpy master\\ILSpy\\bin\\Debug\\net46\\ILSpy.exe", "commandLineArgs": "/separate" } }