Browse Source

#2098: CallBuilder: Fix named argument handling in TI

pull/2113/head
Siegfried Pammer 5 years ago
parent
commit
eea4b7701c
  1. 7
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  3. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

7
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -811,7 +811,7 @@ namespace ICSharpCode.Decompiler.CSharp
// that are no longer required once we add the type arguments. // that are no longer required once we add the type arguments.
// We lend overload resolution a hand by detecting such cases beforehand and requiring type arguments, // We lend overload resolution a hand by detecting such cases beforehand and requiring type arguments,
// if necessary. // if necessary.
if (!CanInferTypeArgumentsFromParameters(method, argumentList.Arguments.SelectArray(a => a.ResolveResult), expressionBuilder.typeInference)) { if (!CanInferTypeArgumentsFromParameters(method, expressionBuilder.typeInference)) {
requireTypeArguments = true; requireTypeArguments = true;
typeArguments = method.TypeArguments.ToArray(); typeArguments = method.TypeArguments.ToArray();
appliedRequireTypeArgumentsShortcut = true; appliedRequireTypeArgumentsShortcut = true;
@ -895,14 +895,13 @@ namespace ICSharpCode.Decompiler.CSharp
return method.IsExtensionMethod && arguments.Count > 0 && arguments[0].Expression is NullReferenceExpression; return method.IsExtensionMethod && arguments.Count > 0 && arguments[0].Expression is NullReferenceExpression;
} }
public static bool CanInferTypeArgumentsFromParameters(IMethod method, IReadOnlyList<ResolveResult> arguments, public static bool CanInferTypeArgumentsFromParameters(IMethod method, TypeInference typeInference)
TypeInference typeInference)
{ {
if (method.TypeParameters.Count == 0) if (method.TypeParameters.Count == 0)
return true; return true;
// always use unspecialized member, otherwise type inference fails // always use unspecialized member, otherwise type inference fails
method = (IMethod)method.MemberDefinition; method = (IMethod)method.MemberDefinition;
typeInference.InferTypeArguments(method.TypeParameters, arguments, method.Parameters.SelectReadOnlyArray(p => p.Type), typeInference.InferTypeArguments(method.TypeParameters, method.Parameters.SelectReadOnlyArray(p => new ResolveResult(p.Type)), method.Parameters.SelectReadOnlyArray(p => p.Type),
out bool success); out bool success);
return success; return success;
} }

2
ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs

@ -424,7 +424,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} else { } else {
TypeInference ti = new TypeInference(compilation, conversions); TypeInference ti = new TypeInference(compilation, conversions);
bool success; bool success;
candidate.InferredTypes = ti.InferTypeArguments(candidate.TypeParameters, arguments, candidate.ParameterTypes, out success, classTypeArguments); candidate.InferredTypes = ti.InferTypeArguments(candidate.TypeParameters, arguments, candidate.ArgumentToParameterMap.SelectReadOnlyArray(parameterIndex => candidate.ParameterTypes[parameterIndex]), out success, classTypeArguments);
if (!success) if (!success)
candidate.AddError(OverloadResolutionErrors.TypeInferenceFailed); candidate.AddError(OverloadResolutionErrors.TypeInferenceFailed);
} }

4
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -378,9 +378,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
if (!targetType.GetAllBaseTypes().Any(i => i.IsKnownType(KnownTypeCode.IEnumerable) || i.IsKnownType(KnownTypeCode.IEnumerableOfT))) if (!targetType.GetAllBaseTypes().Any(i => i.IsKnownType(KnownTypeCode.IEnumerable) || i.IsKnownType(KnownTypeCode.IEnumerableOfT)))
return false; return false;
return CSharp.CallBuilder.CanInferTypeArgumentsFromParameters( return CSharp.CallBuilder.CanInferTypeArgumentsFromParameters(method, new TypeInference(resolveContext.Compilation));
method, method.Parameters.SelectReadOnlyArray(p => new ResolveResult(p.Type)),
new TypeInference(resolveContext.Compilation));
} }
static IType GetReturnTypeFromInstruction(ILInstruction instruction) static IType GetReturnTypeFromInstruction(ILInstruction instruction)

Loading…
Cancel
Save