From 308944456c82b9f88bb617229a9f22a1ff82088c Mon Sep 17 00:00:00 2001 From: CreateAndInject Date: Mon, 22 Apr 2024 07:04:48 +0800 Subject: [PATCH] Pass in genericParamProvider --- src/DotNet/Importer.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/DotNet/Importer.cs b/src/DotNet/Importer.cs index de37e66b6..ab4f424a2 100644 --- a/src/DotNet/Importer.cs +++ b/src/DotNet/Importer.cs @@ -225,8 +225,14 @@ TypeSig ImportAsTypeSig(Type type, Type declaringType, bool? treatAsGenericInst case ElementType.SZArray: return new SZArraySig(ImportAsTypeSig(type.GetElementType(), declaringType)); case ElementType.ValueType: return new ValueTypeSig(CreateTypeDefOrRef(type)); case ElementType.Class: return new ClassSig(CreateTypeDefOrRef(type)); - case ElementType.Var: return new GenericVar((uint)type.GenericParameterPosition, gpContext.Type); - case ElementType.MVar: return new GenericMVar((uint)type.GenericParameterPosition, gpContext.Method); + case ElementType.Var: + if (gpContext.Type is null && IsThisModule(type.Module) && module.ResolveToken(type.DeclaringType.MetadataToken) is TypeDef ownerType) + return new GenericVar((uint)type.GenericParameterPosition, ownerType); + return new GenericVar((uint)type.GenericParameterPosition, gpContext.Type); + case ElementType.MVar: + if (gpContext.Method is null && IsThisModule(type.Module) && module.ResolveToken(type.DeclaringMethod.MetadataToken) is MethodDef ownerMethod) + return new GenericMVar((uint)type.GenericParameterPosition, ownerMethod); + return new GenericMVar((uint)type.GenericParameterPosition, gpContext.Method); case ElementType.I: FixSignature = true; // FnPtr is mapped to System.IntPtr @@ -827,11 +833,11 @@ public TypeSig Import(TypeSig type) { case ElementType.ByRef: result = new ByRefSig(Import(type.Next)); break; case ElementType.ValueType: result = CreateClassOrValueType((type as ClassOrValueTypeSig).TypeDefOrRef, true); break; case ElementType.Class: result = CreateClassOrValueType((type as ClassOrValueTypeSig).TypeDefOrRef, false); break; - case ElementType.Var: result = new GenericVar((type as GenericVar).Number, gpContext.Type); break; + case ElementType.Var: result = new GenericVar((type as GenericVar).Number, gpContext.Type ?? (type as GenericVar).OwnerType); break; case ElementType.ValueArray:result = new ValueArraySig(Import(type.Next), (type as ValueArraySig).Size); break; case ElementType.FnPtr: result = new FnPtrSig(Import((type as FnPtrSig).Signature)); break; case ElementType.SZArray: result = new SZArraySig(Import(type.Next)); break; - case ElementType.MVar: result = new GenericMVar((type as GenericMVar).Number, gpContext.Method); break; + case ElementType.MVar: result = new GenericMVar((type as GenericMVar).Number, gpContext.Method ?? (type as GenericVar).OwnerMethod); break; case ElementType.CModReqd: result = new CModReqdSig(Import((type as ModifierSig).Modifier), Import(type.Next)); break; case ElementType.CModOpt: result = new CModOptSig(Import((type as ModifierSig).Modifier), Import(type.Next)); break; case ElementType.Module: result = new ModuleSig((type as ModuleSig).Index, Import(type.Next)); break;