diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs index 16fadeecf..80631f96a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs @@ -45,6 +45,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Decimal(); Decimal(5m); + +#if CS72 + NamedArgument(flag: true); + NamedArgument(flag: false); +#endif } private void Conflicts() @@ -147,6 +152,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { } + private void NamedArgument(bool flag) + { + } + private string Get(out int a) { throw null; diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il index cc01fe3db..79df342db 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.il @@ -474,6 +474,15 @@ IL_0001: ret } // end of method OptionalArguments::OnlyDifferenceIsLastArgumentCastNecessary + .method private hidebysig instance void + NamedArgument(bool flag) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method OptionalArguments::NamedArgument + .method private hidebysig instance string Get([out] int32& a) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il index e34d0deb9..f4c232fe7 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.il @@ -425,6 +425,14 @@ IL_0000: ret } // end of method OptionalArguments::OnlyDifferenceIsLastArgumentCastNecessary + .method private hidebysig instance void + NamedArgument(bool flag) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method OptionalArguments::NamedArgument + .method private hidebysig instance string Get([out] int32& a) cil managed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il index 179bc8bff..58c97a131 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.opt.roslyn.il @@ -73,7 +73,7 @@ .method private hidebysig instance void SimpleTests() cil managed { - // Code size 64 (0x40) + // Code size 78 (0x4e) .maxstack 3 IL_0000: ldarg.0 IL_0001: ldc.i4.s 10 @@ -98,7 +98,13 @@ IL_0034: ldc.i4.5 IL_0035: newobj instance void [mscorlib]System.Decimal::.ctor(int32) IL_003a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Decimal(valuetype [mscorlib]System.Decimal) - IL_003f: ret + IL_003f: ldarg.0 + IL_0040: ldc.i4.1 + IL_0041: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::NamedArgument(bool) + IL_0046: ldarg.0 + IL_0047: ldc.i4.0 + IL_0048: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::NamedArgument(bool) + IL_004d: ret } // end of method OptionalArguments::SimpleTests .method private hidebysig instance void @@ -401,6 +407,14 @@ IL_0000: ret } // end of method OptionalArguments::OnlyDifferenceIsLastArgumentCastNecessary + .method private hidebysig instance void + NamedArgument(bool flag) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method OptionalArguments::NamedArgument + .method private hidebysig instance string Get([out] int32& a) cil managed { @@ -423,15 +437,16 @@ .size 12 } // end of class '__StaticArrayInitTypeSize=12' - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002DC4 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002DD4 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002DF8 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002E08 } // end of class '' // ============================================================= -.data cil I_00002DC4 = bytearray ( +.data cil I_00002DF8 = bytearray ( 0A 00 00 00 09 00 00 00 08 00 00 00) -.data cil I_00002DD4 = bytearray ( +.data cil I_00002E04 = int8[4] +.data cil I_00002E08 = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00) // *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il index f8f4f8145..ec8a8e11d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.roslyn.il @@ -78,7 +78,7 @@ .method private hidebysig instance void SimpleTests() cil managed { - // Code size 70 (0x46) + // Code size 86 (0x56) .maxstack 3 IL_0000: nop IL_0001: ldarg.0 @@ -109,7 +109,15 @@ IL_003a: newobj instance void [mscorlib]System.Decimal::.ctor(int32) IL_003f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::Decimal(valuetype [mscorlib]System.Decimal) IL_0044: nop - IL_0045: ret + IL_0045: ldarg.0 + IL_0046: ldc.i4.1 + IL_0047: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::NamedArgument(bool) + IL_004c: nop + IL_004d: ldarg.0 + IL_004e: ldc.i4.0 + IL_004f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.OptionalArguments::NamedArgument(bool) + IL_0054: nop + IL_0055: ret } // end of method OptionalArguments::SimpleTests .method private hidebysig instance void @@ -449,6 +457,15 @@ IL_0001: ret } // end of method OptionalArguments::OnlyDifferenceIsLastArgumentCastNecessary + .method private hidebysig instance void + NamedArgument(bool flag) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method OptionalArguments::NamedArgument + .method private hidebysig instance string Get([out] int32& a) cil managed { @@ -472,15 +489,15 @@ .size 12 } // end of class '__StaticArrayInitTypeSize=12' - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002DF4 - .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002E04 + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' '0F3DD643C5167ACFC541F72809FFF828A6E41494' at I_00002E2C + .field static assembly initonly valuetype ''/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_00002E3C } // end of class '' // ============================================================= -.data cil I_00002DF4 = bytearray ( +.data cil I_00002E2C = bytearray ( 0A 00 00 00 09 00 00 00 08 00 00 00) -.data cil I_00002E04 = bytearray ( +.data cil I_00002E3C = bytearray ( 01 00 00 00 02 00 00 00 03 00 00 00) // *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 82d76fcd2..476f67afc 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -593,7 +593,7 @@ namespace ICSharpCode.Decompiler.CSharp parameter = method.Parameters[i - firstParamIndex]; } var arg = expressionBuilder.Translate(callArguments[i], parameter.Type); - if (IsPrimitiveValueThatShouldBeNamedArgument(arg, method)) { + if (IsPrimitiveValueThatShouldBeNamedArgument(arg, method, parameter)) { isPrimitiveValue.Set(arguments.Count); } if (IsOptionalArgument(parameter, arg)) { @@ -644,11 +644,11 @@ namespace ICSharpCode.Decompiler.CSharp return list; } - private bool IsPrimitiveValueThatShouldBeNamedArgument(TranslatedExpression arg, IMethod method) + private bool IsPrimitiveValueThatShouldBeNamedArgument(TranslatedExpression arg, IMethod method, IParameter p) { if (!arg.ResolveResult.IsCompileTimeConstant || method.DeclaringType.IsKnownType(KnownTypeCode.NullableOfT)) return false; - return arg.ResolveResult.Type.IsKnownType(KnownTypeCode.Boolean); + return p.Type.IsKnownType(KnownTypeCode.Boolean); } private bool TransformParamsArgument(ExpectedTargetDetails expectedTargetDetails, ResolveResult targetResolveResult,