Conversation
'this' and 'base' both read the 'this' parameter of the function being decompiled, but their resolve result did not say so: consumers that key on ILVariableResolveResult (local-reference output, highlighting, hover) could not connect the keyword to the variable, and the qualified/unqualified spellings of the same access carried differently shaped annotations. The resolver has no ILFunction and thus no variable to put into a ThisResolveResult, so it stops synthesizing one: LookInCurrentType looks the name up against the (self-parameterized) current type, which grants the same protected access, and the annotation of an unqualified field access is built from the translated target instead. ResolveThisReference and ResolveBaseReference had no callers left and are removed. Assisted-by: Claude:claude-fable-5:Claude Code
christophwille
force-pushed
the
feature/this-resolve-result-ilvariable
branch
from
August 15, 2026 11:17
52dc5cf to
e475e26
Compare
dgrunwald
approved these changes
Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ThisResolveResultnow inherits fromILVariableResolveResultand carries thethisparameter (ILVariablewithKind == Parameter,Index < 0) of the function being decompiled. Everythis/basereference the decompiler emits - explicitthis.x,base.M(), and the target of an unqualifiedx- is annotated with that variable.Analysis
Where
ThisResolveResultwas createdILVariable?ExpressionBuilder.TranslateTarget,basebranchldloc this(orbox T(ldobj T(ldloc this))for structs)ExpressionBuilder.TranslateTarget, explicitthisbranch (added in 13c6cc6 for #3984)ConvertVariablealready annotated theThisReferenceExpressionwith anILVariableResolveResultCSharpResolver.ResolveThisReference()/ResolveBaseReference()CSharpTypeResolveContext, not anILFunctionThe resolver-created one mattered in exactly one place:
LookInCurrentTypeusedResolveThisReference()as the lookup target for simple names in the current type, andExpressionBuilder.ConvertFieldannotated the resultingMemberResolveResulton an unqualified field access. That is whyTransformFieldAndConstructorInitializers.ReferencesInstanceMembersaw aThisResolveResulttarget forAbut (before #3984) not forthis.A.Options considered
thisvariable intoCSharpResolver(WithCurrentThisVariable). Rejected: threads an IL concept through the resolver's immutable-copy constructor and everyWith*method, and still needs a fallback for resolvers created without anILFunction(TypeSystemAstBuilder,IntroduceUsingDeclarations,IntroduceExtensionMethods, static contexts).ILVariableResolveResult. Rejected: breaks the non-null contract every consumer relies on.thisin the resolver; annotate from the translated target instead. Chosen - see below.Why the lookup does not need a
ThisResolveResultMemberLookupusesis ThisResolveResultfor two things: (a) granting protected access, whichIsProtectedAccessAllowed(type)already grants for the current type; (b) rewriting the target of a static member to aTypeResolveResult, which is a no-op when the target already is one. The other consumers ofResolveSimpleNamein the decompiler (CallBuilderoverload checks) only use the member lists.One subtlety surfaced by the Pretty suite (114 failures on the first attempt): the lookup target for the current type must stay self-parameterized (
C<T>rather than the bare definition), otherwise the members come out unspecialized andSpecializedMember.Equals(..., TypeErasure)never matches the specialized members that IL references inside the type resolve to - which made every unqualified access in a generic type look ambiguous and get athis.qualifier.Changes
Semantics/ThisResolveResult.cs-: ILVariableResolveResult; ctor(ILVariable thisVariable, IType type, bool causesNonVirtualInvocation = false). TheTypeis the one the reference is spelled with (base-> base type; structthis-> the struct, while the variable itself is by-ref).IL/Instructions/PatternMatching.cs- newMatchLdThis(out ILVariable? variable); the parameterless overload delegates to it.CSharp/ExpressionBuilder.csTranslateTarget:ShouldUseBaseReference/MatchLdThisreturn the matchedthisvariable for thebasebranch; the explicit-thisbranch takes it from theILVariableResolveResultConvertVariableproduced.ConvertField: an unqualified field access is annotated with the translated target's resolve result (this/base/type) instead of the resolver's synthesized one. This keepsReferencesInstanceMemberseeing aThisResolveResultfor the unqualified spelling (the Primary-constructor conversion emitsthisin a field initializer (CS0027) #3984 fixtureStructInitializerDependsOnFieldcovers this).CSharp/Resolver/CSharpResolver.csLookInCurrentTypelooks names up againstTypeResolveResult(self-parameterized current type).ResolveThisReference()/ResolveBaseReference()removed. They are public, but had no callers left in the repo, and nothing can construct aThisResolveResultwithout anILVariableany more. Flagging this as the one public-API removal in case stubs are preferred.ICSharpCode.Decompiler.Tests/Semantics/ThisResolveResultTests.cs(new) - explicitthis, unqualified field target,base(base type +CausesNonVirtualInvocation), struct by-refthis. All four fail against the pre-change sources (verified by stashing) and pass now.Behavior notes
MemberResolveResult(TypeResolveResult(field.DeclaringType), field)(same as the qualified spelling produces) instead ofTypeResolveResult(currentType). No in-repo consumer distinguishes these.ILSpy/ILSpyXcode referencesThisResolveResultor the removed resolver methods.Test plan
PrettyTestRunner- 1980 passed, 5 skippedThisResolveResultTests- red before, 4/4 green afterILSpy.csprojbuilds🤖 Generated with Claude Code