Browse Source

Recognize a closure struct of a generic method or type

FindRefStructParameters dropped generic instantiations, so a parameter
typed 'ref <>c__DisplayClass0_0<T>' never reached RefStructTypes. Both
consumers therefore missed local functions whose declaring type or method
is generic: the signature test for an obfuscated local function, and
LocalFunctionNeedsAccessibilityChange, which left such a function internal
while its closure struct stayed private - the recompiled output then fails
with CS0051.

Cross-module signatures still drop out, because the generic type part of an
instantiation goes through GetTypeFromReference, which returns nil.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
pull/4062/head
Siegfried Pammer 3 weeks ago
parent
commit
997d2f2db3
  1. 5
      ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

5
ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

@ -873,7 +873,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -873,7 +873,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public TypeDefinitionHandle GetArrayType(TypeDefinitionHandle elementType, ArrayShape shape) => default;
public TypeDefinitionHandle GetFunctionPointerType(MethodSignature<TypeDefinitionHandle> signature) => default;
public TypeDefinitionHandle GetGenericInstantiation(TypeDefinitionHandle genericType, ImmutableArray<TypeDefinitionHandle> typeArguments) => default;
// A closure struct of a generic method or generic declaring type arrives as an instantiation;
// its definition handle is what identifies the struct. Cross-module generic types still drop out,
// because GetTypeFromReference already returned nil for them.
public TypeDefinitionHandle GetGenericInstantiation(TypeDefinitionHandle genericType, ImmutableArray<TypeDefinitionHandle> typeArguments) => genericType;
public TypeDefinitionHandle GetGenericMethodParameter(Unit genericContext, int index) => default;
public TypeDefinitionHandle GetGenericTypeParameter(Unit genericContext, int index) => default;
public TypeDefinitionHandle GetModifiedType(TypeDefinitionHandle modifier, TypeDefinitionHandle unmodifiedType, bool isRequired) => default;

Loading…
Cancel
Save