Browse Source

Revert "#2098: CallBuilder: Fix named argument handling in TI"

This partially reverts commit eea4b7701c.
pull/2113/head
Siegfried Pammer 5 years ago
parent
commit
05c988c5df
  1. 7
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  2. 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, expressionBuilder.typeInference)) { if (!CanInferTypeArgumentsFromParameters(method, argumentList.Arguments.SelectArray(a => a.ResolveResult), expressionBuilder.typeInference)) {
requireTypeArguments = true; requireTypeArguments = true;
typeArguments = method.TypeArguments.ToArray(); typeArguments = method.TypeArguments.ToArray();
appliedRequireTypeArgumentsShortcut = true; appliedRequireTypeArgumentsShortcut = true;
@ -895,13 +895,14 @@ 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, TypeInference typeInference) public static bool CanInferTypeArgumentsFromParameters(IMethod method, IReadOnlyList<ResolveResult> arguments,
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, method.Parameters.SelectReadOnlyArray(p => new ResolveResult(p.Type)), method.Parameters.SelectReadOnlyArray(p => p.Type), typeInference.InferTypeArguments(method.TypeParameters, arguments, method.Parameters.SelectReadOnlyArray(p => p.Type),
out bool success); out bool success);
return success; return success;
} }

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

@ -378,7 +378,9 @@ 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(method, new TypeInference(resolveContext.Compilation)); return CSharp.CallBuilder.CanInferTypeArgumentsFromParameters(
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