Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generics resolving in method overloads search #937

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/DotVVM.Framework.Tests.Common/Binding/ExpressionHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public void Call_FindOverload_Generic_Array(Type resultIdentifierType, Type[] ar
Call_FindOverload_Generic(typeof(MethodsGenericArgumentsResolvingSampleObject4), MethodsGenericArgumentsResolvingSampleObject4.MethodName, argTypes, resultIdentifierType, expectedGenericArgs);
}
[TestMethod]
[DataRow(typeof(int), new Type[] { typeof(int[]) }, new Type[] { typeof(int) })]
public void Call_FindOverload_Generic_Enumerable_Array(Type resultIdentifierType, Type[] argTypes, Type[] expectedGenericArgs)
{
Call_FindOverload_Generic(typeof(MethodsGenericArgumentsResolvingSampleObject6), MethodsGenericArgumentsResolvingSampleObject6.MethodName, argTypes, resultIdentifierType, expectedGenericArgs);
}
[TestMethod]
[DataRow(typeof(GenericTestResult1), new Type[] { typeof(GenericModelSampleObject<int[]>) }, new Type[] { typeof(int) })]
[DataRow(typeof(GenericTestResult2), new Type[] { typeof(List<int>[]) }, new Type[] { typeof(int) })]
public void Call_FindOverload_Generic_Array_Recursive(Type resultIdentifierType, Type[] argTypes, Type[] expectedGenericArgs)
Expand All @@ -130,6 +136,11 @@ public void Call_FindOverload_Generic_Array_Recursive(Type resultIdentifierType,
}
}

public static class MethodsGenericArgumentsResolvingSampleObject6
{
public const string MethodName = nameof(TestMethod);
public static T2 TestMethod<T2>(IEnumerable<T2> a) => default;
}
public static class MethodsGenericArgumentsResolvingSampleObject5
{
public const string MethodName = nameof(TestMethod);
Expand Down
11 changes: 10 additions & 1 deletion src/DotVVM.Framework/Compilation/Binding/ExpressionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,16 @@ private static Type GetGenericParameterType(Type genericArg, Type[] searchedGene
}
else if (sgt.IsGenericType)
{
var value = GetGenericParameterType(genericArg, sgt.GetGenericArguments(), expressionTypes[i].GetGenericArguments());
Type[] genericArguments;
var expression = expressionTypes[i];

// Arrays need to be handled in a special way to obtain instantiation
if (expression.IsArray)
genericArguments = new[] { expression.GetElementType() };
else
genericArguments = expression.GetGenericArguments();

var value = GetGenericParameterType(genericArg, sgt.GetGenericArguments(), genericArguments);
if (value is Type) return value;
}
}
Expand Down