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

4
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -216,7 +216,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// Gets whether the type is the specified known type. /// 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> /// </summary>
public static bool IsKnownType(this IType type, KnownTypeCode knownType) public static bool IsKnownType(this IType type, KnownTypeCode knownType)
{ {
@ -226,7 +226,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// Gets whether the type is the specified known type. /// 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> /// </summary>
internal static bool IsKnownType(this IType type, KnownAttribute knownType) internal static bool IsKnownType(this IType type, KnownAttribute knownType)
{ {

Loading…
Cancel
Save