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

Ensure emitted method signatures have the correct generic parameter count #391

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
2 changes: 2 additions & 0 deletions Cpp2IL.Core/Model/Contexts/MethodAnalysisContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class MethodAnalysisContext : HasCustomAttributesAndName, IMethodInfoProv

public int ParameterCount => Parameters.Count;

public int GenericParameterCount => Definition?.GenericContainer?.genericParameterCount ?? 0;

//TODO Support custom attributes on return types (v31 feature)
public TypeAnalysisContext ReturnTypeContext => InjectedReturnType ?? DeclaringType!.DeclaringAssembly.ResolveIl2CppType(Definition!.RawReturnType!);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ private static void CopyMethodsInType(ReferenceImporter importer, TypeAnalysisCo
}


var signature = methodCtx.IsStatic ? MethodSignature.CreateStatic(returnType, parameterTypes) : MethodSignature.CreateInstance(returnType, parameterTypes);
var signature = methodCtx.IsStatic
? MethodSignature.CreateStatic(returnType, methodCtx.GenericParameterCount, parameterTypes)
: MethodSignature.CreateInstance(returnType, methodCtx.GenericParameterCount, parameterTypes);

var managedMethod = new MethodDefinition(methodCtx.Name, (MethodAttributes)methodCtx.Attributes, signature);

Expand Down
6 changes: 2 additions & 4 deletions Cpp2IL.Core/Utils/AsmResolver/ContextToMethodDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ private static MethodSignature ToMethodSignature(this MethodAnalysisContext cont
var returnType = context.ReturnTypeContext.ToTypeSignature(parentModule);
var parameters = context.Parameters.Select(p => p.ToTypeSignature(parentModule));

var genericParameterCount = context.Definition?.GenericContainer?.genericParameterCount ?? 0;

return context.IsStatic
? MethodSignature.CreateStatic(returnType, genericParameterCount, parameters)
: MethodSignature.CreateInstance(returnType, genericParameterCount, parameters);
? MethodSignature.CreateStatic(returnType, context.GenericParameterCount, parameters)
: MethodSignature.CreateInstance(returnType, context.GenericParameterCount, parameters);
}

public static IMethodDescriptor ToMethodDescriptor(this MethodAnalysisContext context, ModuleDefinition parentModule)
Expand Down
Loading