Skip to content

Commit

Permalink
Ensure emitted method signatures have the correct generic parameter c…
Browse files Browse the repository at this point in the history
…ount (#391)
  • Loading branch information
ds5678 authored Dec 12, 2024
1 parent 896d6c3 commit 4def87e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit 4def87e

Please sign in to comment.