diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs index d655327b3..ba9ca3afe 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs @@ -179,5 +179,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty CustCount = g.Count() }; } + + public object Issue437(bool[] bools) + { + return from x in bools + where x + select (x); + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.il index c8b0d5076..d54c373b8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.il @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly o43t14jy +.assembly vhzzjbo3 { .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 @@ -25,15 +25,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module o43t14jy.dll -// MVID: {6BAE605B-B0FE-4E01-BE5E-39B7D00E7902} +.module vhzzjbo3.dll +// MVID: {BE1CCC70-BCCD-4D60-B953-95795349E24D} .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: 0x03170000 +// Image base: 0x00C80000 // =============== CLASS MEMBERS DECLARATION =================== @@ -183,6 +183,10 @@ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field private static class [mscorlib]System.Func`2,class '<>f__AnonymousTypee`2'> 'CS$<>9__CachedAnonymousMethodDelegate5e' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate61' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate62' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method public hidebysig instance object MultipleWhere() cil managed { @@ -915,6 +919,47 @@ IL_0053: ret } // end of method QueryExpressions::QueryContinuation + .method public hidebysig instance object + Issue437(bool[] bools) cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_0007: brtrue.s IL_001c + + IL_0009: ldnull + IL_000a: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'b__5f'(bool) + IL_0010: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0015: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_001a: br.s IL_001c + + IL_001c: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_0021: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0026: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_002b: brtrue.s IL_0040 + + IL_002d: ldnull + IL_002e: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'b__60'(bool) + IL_0034: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0039: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_003e: br.s IL_0040 + + IL_0040: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_0045: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Select(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_004a: stloc.0 + IL_004b: br.s IL_004d + + IL_004d: ldloc.0 + IL_004e: ret + } // end of method QueryExpressions::Issue437 + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -1723,6 +1768,34 @@ IL_0015: ret } // end of method QueryExpressions::'b__5c' + .method private hidebysig static bool 'b__5f'(bool x) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 6 (0x6) + .maxstack 1 + .locals init (bool V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0004 + + IL_0004: ldloc.0 + IL_0005: ret + } // end of method QueryExpressions::'b__5f' + + .method private hidebysig static bool 'b__60'(bool x) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 6 (0x6) + .maxstack 1 + .locals init (bool V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0004 + + IL_0004: ldloc.0 + IL_0005: ret + } // end of method QueryExpressions::'b__60' + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions .class private auto ansi sealed beforefieldinit '<>f__AnonymousType0`3'<'j__TPar','j__TPar','j__TPar'> @@ -4739,4 +4812,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\QueryExpressions.res +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\QueryExpressions.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.il index fedb30f4b..9a449a930 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.il @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '42zjmgbc' +.assembly lt0pgaxw { .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 @@ -25,15 +25,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '42zjmgbc.dll' -// MVID: {9BD10752-1FE2-4FB9-B5D1-63D7002B8838} +.module lt0pgaxw.dll +// MVID: {5B327896-F57D-407B-A721-D34CFB65CA7C} .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: 0x01610000 +// Image base: 0x03000000 // =============== CLASS MEMBERS DECLARATION =================== @@ -183,6 +183,10 @@ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field private static class [mscorlib]System.Func`2,class '<>f__AnonymousTypee`2'> 'CS$<>9__CachedAnonymousMethodDelegate5e' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate61' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field private static class [mscorlib]System.Func`2 'CS$<>9__CachedAnonymousMethodDelegate62' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method public hidebysig instance object MultipleWhere() cil managed { @@ -757,6 +761,37 @@ IL_004a: ret } // end of method QueryExpressions::QueryContinuation + .method public hidebysig instance object + Issue437(bool[] bools) cil managed + { + // Code size 70 (0x46) + .maxstack 3 + IL_0000: ldarg.1 + IL_0001: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_0006: brtrue.s IL_0019 + + IL_0008: ldnull + IL_0009: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'b__5f'(bool) + IL_000f: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0014: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_0019: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61' + IL_001e: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0023: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_0028: brtrue.s IL_003b + + IL_002a: ldnull + IL_002b: ldftn bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'b__60'(bool) + IL_0031: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0036: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_003b: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62' + IL_0040: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Select(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0045: ret + } // end of method QueryExpressions::Issue437 + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { @@ -1358,6 +1393,24 @@ IL_0011: ret } // end of method QueryExpressions::'b__5c' + .method private hidebysig static bool 'b__5f'(bool x) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } // end of method QueryExpressions::'b__5f' + + .method private hidebysig static bool 'b__60'(bool x) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } // end of method QueryExpressions::'b__60' + } // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions .class private auto ansi sealed beforefieldinit '<>f__AnonymousType0`3'<'j__TPar','j__TPar','j__TPar'> @@ -3964,4 +4017,4 @@ // ============================================================= // *********** DISASSEMBLY COMPLETE *********************** -// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\QueryExpressions.opt.res +// WARNING: Created Win32 resource file ../../../TestCases/Pretty\QueryExpressions.opt.res diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.roslyn.il index 02babaea5..20f8dcae5 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module QueryExpressions.dll -// MVID: {CD7623F3-CC98-434E-A3C5-16D9445968AB} +// MVID: {3A5F3986-5A3B-4A28-AEB6-FB53EAEF5C5A} .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: 0x00E10000 +// Image base: 0x00AF0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -3218,6 +3218,8 @@ .field public static class [mscorlib]System.Func`2 '<>9__16_0' .field public static class [mscorlib]System.Func`2 '<>9__17_0' .field public static class [mscorlib]System.Func`2,class '<>f__AnonymousType14`2'> '<>9__17_1' + .field public static class [mscorlib]System.Func`2 '<>9__18_0' + .field public static class [mscorlib]System.Func`2 '<>9__18_1' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -3795,6 +3797,24 @@ IL_0011: ret } // end of method '<>c'::'b__17_1' + .method assembly hidebysig instance bool + 'b__18_0'(bool x) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method '<>c'::'b__18_0' + + .method assembly hidebysig instance bool + 'b__18_1'(bool x) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method '<>c'::'b__18_1' + } // end of class '<>c' .field public class [mscorlib]System.Collections.Generic.IEnumerable`1 customers @@ -4453,6 +4473,41 @@ IL_004e: ret } // end of method QueryExpressions::QueryContinuation + .method public hidebysig instance object + Issue437(bool[] bools) cil managed + { + // Code size 74 (0x4a) + .maxstack 3 + IL_0000: ldarg.1 + IL_0001: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0' + IL_0006: dup + IL_0007: brtrue.s IL_0020 + + IL_0009: pop + IL_000a: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9' + IL_000f: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'b__18_0'(bool) + IL_0015: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_001a: dup + IL_001b: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0' + IL_0020: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0025: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1' + IL_002a: dup + IL_002b: brtrue.s IL_0044 + + IL_002d: pop + IL_002e: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9' + IL_0033: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'b__18_1'(bool) + IL_0039: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_003e: dup + IL_003f: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1' + IL_0044: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Select(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0049: ret + } // end of method QueryExpressions::Issue437 + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.roslyn.il index 75f7a98f1..9762d4380 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module QueryExpressions.dll -// MVID: {DACBCB5E-2B45-4162-A8DF-E6E0CBF3C641} +// MVID: {38FA88A1-A1FA-45E9-87D6-D5C50B7535C2} .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: 0x02DB0000 +// Image base: 0x029D0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -3303,6 +3303,8 @@ .field public static class [mscorlib]System.Func`2 '<>9__16_0' .field public static class [mscorlib]System.Func`2 '<>9__17_0' .field public static class [mscorlib]System.Func`2,class '<>f__AnonymousType14`2'> '<>9__17_1' + .field public static class [mscorlib]System.Func`2 '<>9__18_0' + .field public static class [mscorlib]System.Func`2 '<>9__18_1' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -3881,6 +3883,24 @@ IL_0011: ret } // end of method '<>c'::'b__17_1' + .method assembly hidebysig instance bool + 'b__18_0'(bool x) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method '<>c'::'b__18_0' + + .method assembly hidebysig instance bool + 'b__18_1'(bool x) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method '<>c'::'b__18_1' + } // end of class '<>c' .field public class [mscorlib]System.Collections.Generic.IEnumerable`1 customers @@ -4617,6 +4637,47 @@ IL_0053: ret } // end of method QueryExpressions::QueryContinuation + .method public hidebysig instance object + Issue437(bool[] bools) cil managed + { + // Code size 79 (0x4f) + .maxstack 3 + .locals init (object V_0) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0' + IL_0007: dup + IL_0008: brtrue.s IL_0021 + + IL_000a: pop + IL_000b: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9' + IL_0010: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'b__18_0'(bool) + IL_0016: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_001b: dup + IL_001c: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0' + IL_0021: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_0026: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1' + IL_002b: dup + IL_002c: brtrue.s IL_0045 + + IL_002e: pop + IL_002f: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9' + IL_0034: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'b__18_1'(bool) + IL_003a: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_003f: dup + IL_0040: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1' + IL_0045: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Select(class [mscorlib]System.Collections.Generic.IEnumerable`1, + class [mscorlib]System.Func`2) + IL_004a: stloc.0 + IL_004b: br.s IL_004d + + IL_004d: ldloc.0 + IL_004e: ret + } // end of method QueryExpressions::Issue437 + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs index fc92b8783..1be532a46 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs @@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms if (MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out body)) { QueryExpression query = new QueryExpression(); query.Clauses.Add(new QueryFromClause { Identifier = parameterName, Expression = mre.Target.Detach() }); - query.Clauses.Add(new QuerySelectClause { Expression = body.Detach() }); + query.Clauses.Add(new QuerySelectClause { Expression = WrapExpressionInParenthesesIfNecessary(body.Detach(), parameterName) }); return query; } return null; @@ -143,7 +143,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms QueryExpression query = new QueryExpression(); query.Clauses.Add(new QueryFromClause { Identifier = p1.Name, Expression = mre.Target.Detach() }); query.Clauses.Add(new QueryFromClause { Identifier = p2.Name, Expression = collectionSelector.Detach() }); - query.Clauses.Add(new QuerySelectClause { Expression = ((Expression)lambda.Body).Detach() }); + query.Clauses.Add(new QuerySelectClause { Expression = WrapExpressionInParenthesesIfNecessary(((Expression)lambda.Body).Detach(), parameterName) }); return query; } } @@ -242,7 +242,20 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return null; } } - + + /// + /// This fixes #437: Decompilation of query expression loses material parentheses + /// We wrap the expression in parentheses if: + /// - the Select-call is explicit (see caller(s)) + /// - the expression is a plain identifier matching the parameter name + /// + Expression WrapExpressionInParenthesesIfNecessary(Expression expression, string parameterName) + { + if (expression is IdentifierExpression ident && parameterName.Equals(ident.Identifier, StringComparison.Ordinal)) + return new ParenthesizedExpression(expression); + return expression; + } + /// /// Ensure that all ThenBy's are correct, and that the list of ThenBy's is terminated by an 'OrderBy' invocation. ///