Browse Source

Fix #437: Decompilation of query expression loses material parentheses

pull/900/head
Siegfried Pammer 8 years ago
parent
commit
fb21870cff
  1. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs
  2. 83
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.il
  3. 63
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.il
  4. 59
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.opt.roslyn.il
  5. 65
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.roslyn.il
  6. 19
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs

7
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);
}
}
}

83
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 [System.Core]System.Linq.IGrouping`2<string,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer>,class '<>f__AnonymousTypee`2'<string,int32>> 'CS$<>9__CachedAnonymousMethodDelegate5e'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<bool,bool> 'CS$<>9__CachedAnonymousMethodDelegate61'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<bool,bool> '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<bool,bool> 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::'<Issue437>b__5f'(bool)
IL_0010: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_0015: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61'
IL_001a: br.s IL_001c
IL_001c: ldsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61'
IL_0021: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_0026: ldsfld class [mscorlib]System.Func`2<bool,bool> 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::'<Issue437>b__60'(bool)
IL_0034: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_0039: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62'
IL_003e: br.s IL_0040
IL_0040: ldsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62'
IL_0045: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!1> [System.Core]System.Linq.Enumerable::Select<bool,bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,!!1>)
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::'<QueryContinuation>b__5c'
.method private hidebysig static bool '<Issue437>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::'<Issue437>b__5f'
.method private hidebysig static bool '<Issue437>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::'<Issue437>b__60'
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType0`3'<'<Name>j__TPar','<OrderID>j__TPar','<Total>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

63
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 [System.Core]System.Linq.IGrouping`2<string,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer>,class '<>f__AnonymousTypee`2'<string,int32>> 'CS$<>9__CachedAnonymousMethodDelegate5e'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<bool,bool> 'CS$<>9__CachedAnonymousMethodDelegate61'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<bool,bool> '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<bool,bool> 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::'<Issue437>b__5f'(bool)
IL_000f: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_0014: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61'
IL_0019: ldsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate61'
IL_001e: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_0023: ldsfld class [mscorlib]System.Func`2<bool,bool> 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::'<Issue437>b__60'(bool)
IL_0031: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_0036: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62'
IL_003b: ldsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions::'CS$<>9__CachedAnonymousMethodDelegate62'
IL_0040: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!1> [System.Core]System.Linq.Enumerable::Select<bool,bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,!!1>)
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::'<QueryContinuation>b__5c'
.method private hidebysig static bool '<Issue437>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::'<Issue437>b__5f'
.method private hidebysig static bool '<Issue437>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::'<Issue437>b__60'
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType0`3'<'<Name>j__TPar','<OrderID>j__TPar','<Total>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

59
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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer,bool> '<>9__16_0'
.field public static class [mscorlib]System.Func`2<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer,string> '<>9__17_0'
.field public static class [mscorlib]System.Func`2<class [System.Core]System.Linq.IGrouping`2<string,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer>,class '<>f__AnonymousType14`2'<string,int32>> '<>9__17_1'
.field public static class [mscorlib]System.Func`2<bool,bool> '<>9__18_0'
.field public static class [mscorlib]System.Func`2<bool,bool> '<>9__18_1'
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
@ -3795,6 +3797,24 @@
IL_0011: ret
} // end of method '<>c'::'<QueryContinuation>b__17_1'
.method assembly hidebysig instance bool
'<Issue437>b__18_0'(bool x) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ret
} // end of method '<>c'::'<Issue437>b__18_0'
.method assembly hidebysig instance bool
'<Issue437>b__18_1'(bool x) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ret
} // end of method '<>c'::'<Issue437>b__18_1'
} // end of class '<>c'
.field public class [mscorlib]System.Collections.Generic.IEnumerable`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer> 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<bool,bool> 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'::'<Issue437>b__18_0'(bool)
IL_0015: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_001a: dup
IL_001b: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0'
IL_0020: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_0025: ldsfld class [mscorlib]System.Func`2<bool,bool> 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'::'<Issue437>b__18_1'(bool)
IL_0039: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_003e: dup
IL_003f: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1'
IL_0044: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!1> [System.Core]System.Linq.Enumerable::Select<bool,bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,!!1>)
IL_0049: ret
} // end of method QueryExpressions::Issue437
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

65
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<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer,bool> '<>9__16_0'
.field public static class [mscorlib]System.Func`2<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer,string> '<>9__17_0'
.field public static class [mscorlib]System.Func`2<class [System.Core]System.Linq.IGrouping`2<string,class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer>,class '<>f__AnonymousType14`2'<string,int32>> '<>9__17_1'
.field public static class [mscorlib]System.Func`2<bool,bool> '<>9__18_0'
.field public static class [mscorlib]System.Func`2<bool,bool> '<>9__18_1'
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
@ -3881,6 +3883,24 @@
IL_0011: ret
} // end of method '<>c'::'<QueryContinuation>b__17_1'
.method assembly hidebysig instance bool
'<Issue437>b__18_0'(bool x) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ret
} // end of method '<>c'::'<Issue437>b__18_0'
.method assembly hidebysig instance bool
'<Issue437>b__18_1'(bool x) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ret
} // end of method '<>c'::'<Issue437>b__18_1'
} // end of class '<>c'
.field public class [mscorlib]System.Collections.Generic.IEnumerable`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/Customer> 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<bool,bool> 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'::'<Issue437>b__18_0'(bool)
IL_0016: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_001b: dup
IL_001c: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_0'
IL_0021: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_0026: ldsfld class [mscorlib]System.Func`2<bool,bool> 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'::'<Issue437>b__18_1'(bool)
IL_003a: newobj instance void class [mscorlib]System.Func`2<bool,bool>::.ctor(object,
native int)
IL_003f: dup
IL_0040: stsfld class [mscorlib]System.Func`2<bool,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.QueryExpressions/'<>c'::'<>9__18_1'
IL_0045: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!1> [System.Core]System.Linq.Enumerable::Select<bool,bool>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,!!1>)
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
{

19
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;
}
}
/// <summary>
/// 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
/// </summary>
Expression WrapExpressionInParenthesesIfNecessary(Expression expression, string parameterName)
{
if (expression is IdentifierExpression ident && parameterName.Equals(ident.Identifier, StringComparison.Ordinal))
return new ParenthesizedExpression(expression);
return expression;
}
/// <summary>
/// Ensure that all ThenBy's are correct, and that the list of ThenBy's is terminated by an 'OrderBy' invocation.
/// </summary>

Loading…
Cancel
Save