Skip to content

Commit

Permalink
resolved Ourpalm#257
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Jan 25, 2019
1 parent 6124f0e commit a3c9ac4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
22 changes: 11 additions & 11 deletions ILRuntime/CLR/Method/ILMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ bool CheckHasGenericParamter(object token)
{
TypeReference _ref = ((TypeReference)token);
if (_ref.IsArray)
return CheckHasGenericParamter(_ref.GetElementType());
return CheckHasGenericParamter(((ArrayType)_ref).ElementType);
if (_ref.IsGenericParameter)
return true;
if (_ref.IsGenericInstance)
Expand Down Expand Up @@ -577,16 +577,16 @@ void InitParameters()
bool isArray = false;
int rank = 1;
TypeReference pt = i.ParameterType;
if (i.ParameterType.IsByReference)
if (pt.IsByReference)
{
isByRef = true;
pt = pt.GetElementType();
pt = ((ByReferenceType)pt).ElementType;
}
if (i.ParameterType.IsArray)
if (pt.IsArray)
{
isArray = true;
rank = ((ArrayType)pt).Rank;
pt = pt.GetElementType();
pt = ((ArrayType)pt).ElementType;
}
if (pt.IsGenericParameter)
{
Expand All @@ -609,14 +609,14 @@ void InitParameters()
else
throw new NotSupportedException("Cannot find Generic Parameter " + pt.Name + " in " + def.FullName);
}

if (isByRef)
type = type.MakeByRefType();
if (isArray)
type = type.MakeArrayType(rank);
}
else
type = appdomain.GetType(i.ParameterType, declaringType, this);
type = appdomain.GetType(pt, declaringType, this);

if (isByRef)
type = type.MakeByRefType();
if (isArray)
type = type.MakeArrayType(rank);
parameters.Add(type);
}
}
Expand Down
6 changes: 3 additions & 3 deletions ILRuntime/CLR/TypeSystem/ILType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void RetriveDefinitino(TypeReference def)
definition = null;
}
else
RetriveDefinitino(def.GetElementType());
RetriveDefinitino(((TypeSpecification)def).ElementType);
}
else
definition = def as TypeDefinition;
Expand Down Expand Up @@ -517,7 +517,7 @@ void InitializeBaseType()
if (definition.BaseType.IsGenericInstance)
{
GenericInstanceType git = definition.BaseType as GenericInstanceType;
var elementType = appdomain.GetType(definition.BaseType.GetElementType(), this, null);
var elementType = appdomain.GetType(git.ElementType, this, null);
if (elementType is CLRType)
{
for (int i = 0; i < git.GenericArguments.Count; i++)
Expand All @@ -536,7 +536,7 @@ void InitializeBaseType()
if (specialProcess)
{
//如果泛型参数是自身,则必须要特殊处理,否则会StackOverflow
var elementType = appdomain.GetType(definition.BaseType.GetElementType(), this, null);
var elementType = appdomain.GetType(((GenericInstanceType)definition.BaseType).ElementType, this, null);
foreach (var i in appdomain.CrossBindingAdaptors)
{
if (i.Key.IsGenericType && !i.Key.IsGenericTypeDefinition)
Expand Down
2 changes: 1 addition & 1 deletion ILRuntime/CLR/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static List<IType> GetParamList(this MethodReference def, ILRuntime.Runti
if ((t == null && def.IsGenericInstance) || (t != null && t.HasGenericParameter))
{
GenericInstanceMethod gim = (GenericInstanceMethod)def;
string name = i.ParameterType.IsByReference ? i.ParameterType.GetElementType().FullName : i.ParameterType.FullName;
string name = i.ParameterType.IsByReference ? ((ByReferenceType)i.ParameterType).ElementType.FullName : i.ParameterType.FullName;

for (int j = 0; j < gim.GenericArguments.Count; j++)
{
Expand Down
4 changes: 2 additions & 2 deletions ILRuntime/Runtime/Enviorment/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ internal IType GetType(object token, IType contextType, IMethod contextMethod)
}
if (_ref.IsByReference)
{
var et = _ref.GetElementType();
var et = ((ByReferenceType)_ref).ElementType;
bool valid = !et.ContainsGenericParameter;
var t = GetType(et, contextType, contextMethod);
if (t != null)
Expand All @@ -750,7 +750,7 @@ internal IType GetType(object token, IType contextType, IMethod contextMethod)
if (_ref.IsArray)
{
ArrayType at = (ArrayType)_ref;
var t = GetType(_ref.GetElementType(), contextType, contextMethod);
var t = GetType(at.ElementType, contextType, contextMethod);
if (t != null)
{
res = t.MakeArrayType(at.Rank);
Expand Down
5 changes: 5 additions & 0 deletions ILRuntimeTest/TestFramework/GenericExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ILRuntime.Other;

Expand Down Expand Up @@ -38,5 +39,9 @@ public static void StaticMethod(Func<Task> func) { }
public static void StaticMethod(Func<ExtensionClass, Task> func) { }
public static void StaticMethod<TValue>(Func<Task<TValue>> func) { }
public static void StaticMethod<TValue>(Func<ExtensionClass, Task<TValue>> func) { }
public static void Method(string name, params KeyValuePair<string, string[]>[] panels)
{
Console.WriteLine("进来了");
}
}
}
5 changes: 5 additions & 0 deletions TestCases/GenericMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,10 @@ public static void GenericStaticMethodTest11()
a.TestMethod(out aa);
b.TestMethod(out bb);
}

public static void GenericStaticMethodTest12()
{
ILRuntimeTest.TestBase.StaticGenericMethods.Method("");
}
}
}

0 comments on commit a3c9ac4

Please sign in to comment.