Qualify shadowed instance field loads with this.#607
Merged
Conversation
The decompiler printed an instance field load as the bare field name, so
when a parameter or local shadowed the field (e.g. int Foo(int _x) =>
this._x + _x) the recompiled name bound to the local, not the field. The
compile-back oracle flagged Shadowed reading the parameter twice instead
of the field.
Render this.{field} when the field name collides with a parameter or
local in scope, matching the existing auto-property backing-field branch;
unshadowed fields stay bare per the taste convention. CfgSampleClass goes
from 82 to 83 opcode-exact under --compile-back.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
richlander
added a commit
that referenced
this pull request
Jun 18, 2026
The compile-back oracle (decompile -> recompile -> compare IL) only ran as a console exploration mode in the harness. Wire it into CI as a durable regression guard. Expose CompileBack.Evaluate: a non-printing, structured-result entry point that shares all of the skeleton-emission and opcode-comparison machinery with the existing console Run, so the two paths cannot drift. The test project links the single CompileBack.cs source file (rather than taking a project reference on the harness Exe, which would pull in a second entry point) and adds the Roslyn package it needs. CompileBackGateTests asserts two properties over CfgSampleClass: - no method newly recompiles to a different opcode stream beyond the documented KnownDiffs docket (catches a fix in one method silently degrading another); - previously-fixed methods (CheckedAdd #604, UnsignedShift #606, Shadowed #607) stay opcode-exact. Shrink KnownDiffs as docket entries are fixed; StaleFieldRead remains a tracked defect (issue #605). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
The decompiler printed an instance field load as the bare field name. When a
parameter or local shadows the field, the bare name binds to the local instead
of the field. The compile-back oracle caught this on the
Shadowedfixture:decompiled to
return _shadowed + _shadowed;— reading the parameter twice anddropping the
this._shadowedfield load entirely. Invisible to--compile-checkand
--grade-sourcebecause the output still parses and binds; only the ILdiffers.
Fix
In
CSharpPrinter.FieldTarget, renderthis.{field}for athis-receiverinstance field load when the field name collides with a parameter or local in
scope; unshadowed fields stay bare per the taste convention. This mirrors the
existing auto-property backing-field branch, which already qualifies with
this.for the same shadowing reason.
Verification
--compile-backonCfgSampleClass: opcode-exact goes from 82 to 83; theShadoweddocket entry is resolved.IrImporterTests.Shadowed_QualifiesFieldLoadWhenParameterShadows.ILInspector.Decompiler.Testssuite green (425 passing).Part of the compile-back oracle docket (#604). Related: #605.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com