|
|
|
@ -397,20 +397,25 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
/// Returns false when expectedArgument and passedArgument are incompatible, otherwise true
|
|
|
|
/// Returns false when expectedArgument and passedArgument are incompatible, otherwise true
|
|
|
|
/// is returned (true is used both for successful inferring and other kind of errors).
|
|
|
|
/// is returned (true is used both for successful inferring and other kind of errors).
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// The C# spec (§ 25.6.4) has a bug: it says that type inference works if the passedArgument is IEnumerable{T}
|
|
|
|
|
|
|
|
/// and the expectedArgument is an array; passedArgument and expectedArgument must be swapped here.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
public static bool InferTypeArgument(IReturnType expectedArgument, IReturnType passedArgument, IReturnType[] outputArray) |
|
|
|
public static bool InferTypeArgument(IReturnType expectedArgument, IReturnType passedArgument, IReturnType[] outputArray) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (expectedArgument == null) return true; |
|
|
|
if (expectedArgument == null) return true; |
|
|
|
if (passedArgument == null) return true; // TODO: NullTypeReference
|
|
|
|
if (passedArgument == null || passedArgument == NullReturnType.Instance) return true; |
|
|
|
if (expectedArgument.IsArrayReturnType) { |
|
|
|
|
|
|
|
IReturnType expectedArrayElementType = expectedArgument.CastToArrayReturnType().ArrayElementType; |
|
|
|
if (passedArgument.IsArrayReturnType) { |
|
|
|
if (passedArgument.IsArrayReturnType && expectedArgument.CastToArrayReturnType().ArrayDimensions == passedArgument.CastToArrayReturnType().ArrayDimensions) { |
|
|
|
IReturnType passedArrayElementType = passedArgument.CastToArrayReturnType().ArrayElementType; |
|
|
|
return InferTypeArgument(expectedArrayElementType, passedArgument.CastToArrayReturnType().ArrayElementType, outputArray); |
|
|
|
if (expectedArgument.IsArrayReturnType && expectedArgument.CastToArrayReturnType().ArrayDimensions == passedArgument.CastToArrayReturnType().ArrayDimensions) { |
|
|
|
} else if (passedArgument.IsConstructedReturnType) { |
|
|
|
return InferTypeArgument(expectedArgument.CastToArrayReturnType().ArrayElementType, passedArrayElementType, outputArray); |
|
|
|
switch (passedArgument.FullyQualifiedName) { |
|
|
|
} else if (expectedArgument.IsConstructedReturnType) { |
|
|
|
|
|
|
|
switch (expectedArgument.FullyQualifiedName) { |
|
|
|
case "System.Collections.Generic.IList": |
|
|
|
case "System.Collections.Generic.IList": |
|
|
|
case "System.Collections.Generic.ICollection": |
|
|
|
case "System.Collections.Generic.ICollection": |
|
|
|
case "System.Collections.Generic.IEnumerable": |
|
|
|
case "System.Collections.Generic.IEnumerable": |
|
|
|
return InferTypeArgument(expectedArrayElementType, passedArgument.CastToConstructedReturnType().TypeArguments[0], outputArray); |
|
|
|
return InferTypeArgument(expectedArgument.CastToConstructedReturnType().TypeArguments[0], passedArrayElementType, outputArray); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// If P is an array type, and A is not an array type of the same rank,
|
|
|
|
// If P is an array type, and A is not an array type of the same rank,
|
|
|
|
|