Browse Source

Fix implementation of CallBuilder.IsOptionalArgument by converting the ResolveResult to the parameter type.

pull/1322/head
Siegfried Pammer 7 years ago
parent
commit
982c71efb2
  1. 10
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  2. 4
      ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

10
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -593,7 +593,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -593,7 +593,7 @@ namespace ICSharpCode.Decompiler.CSharp
parameter = method.Parameters[i - firstParamIndex];
}
var arg = expressionBuilder.Translate(callArguments[i], parameter.Type);
if (IsPrimitiveValueThatShouldHaveNamedArgument(arg, method)) {
if (IsPrimitiveValueThatShouldBeNamedArgument(arg, method)) {
isPrimitiveValue.Set(arguments.Count);
}
if (IsOptionalArgument(parameter, arg)) {
@ -644,7 +644,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -644,7 +644,7 @@ namespace ICSharpCode.Decompiler.CSharp
return list;
}
private bool IsPrimitiveValueThatShouldHaveNamedArgument(TranslatedExpression arg, IMethod method)
private bool IsPrimitiveValueThatShouldBeNamedArgument(TranslatedExpression arg, IMethod method)
{
if (!arg.ResolveResult.IsCompileTimeConstant || method.DeclaringType.IsKnownType(KnownTypeCode.NullableOfT))
return false;
@ -714,8 +714,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -714,8 +714,10 @@ namespace ICSharpCode.Decompiler.CSharp
|| a.AttributeType.IsKnownType(KnownAttribute.CallerFilePath)
|| a.AttributeType.IsKnownType(KnownAttribute.CallerLineNumber)))
return false;
return (parameter.ConstantValue == null && arg.ResolveResult.ConstantValue == null)
|| (parameter.ConstantValue != null && parameter.ConstantValue.Equals(arg.ResolveResult.ConstantValue));
if (parameter.ConstantValue == null)
return arg.ResolveResult.ConstantValue == null;
arg = arg.ConvertTo(parameter.Type, expressionBuilder, allowImplicitConversion: true);
return parameter.ConstantValue.Equals(arg.ResolveResult.ConstantValue);
}
[Flags]

4
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -216,7 +216,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -216,7 +216,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Gets whether the type is the specified known type.
/// For generic known types, this returns true any parameterization of the type (and also for the definition itself).
/// For generic known types, this returns true for any parameterization of the type (and also for the definition itself).
/// </summary>
public static bool IsKnownType(this IType type, KnownTypeCode knownType)
{
@ -226,7 +226,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -226,7 +226,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Gets whether the type is the specified known type.
/// For generic known types, this returns true any parameterization of the type (and also for the definition itself).
/// For generic known types, this returns true for any parameterization of the type (and also for the definition itself).
/// </summary>
internal static bool IsKnownType(this IType type, KnownAttribute knownType)
{

Loading…
Cancel
Save