Print the init-only marker after the set keyword again - #4001
Open
siegfriedpammer wants to merge 1 commit into
Open
Print the init-only marker after the set keyword again#4001siegfriedpammer wants to merge 1 commit into
siegfriedpammer wants to merge 1 commit into
Conversation
Comments used to be child nodes flushed by InsertSpecialsDecorator when the next node started printing, which put the marker of an init-only setter right after the keyword. In the slot AST comments are leading/trailing trivia, so the accessor's trailing trivia moved the marker behind the accessor body. The placement cannot go back to trivia on the body either: the auto-property transform drops the body, and the marker with it. The accessor now carries the init-only fact itself and the printer writes the marker next to the keyword. Assisted-by: Claude:claude-opus-5:Claude Code
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.
When init accessors are unavailable (e.g.
-lv CSharp8_0, or the setting turned off), aninit-only setter decompiles as
setplus an/*init*/marker. The marker used to sit rightafter the keyword; since the slot AST migration it lands after the accessor body:
Comments used to be child nodes that
InsertSpecialsDecoratorflushed when the next nodestarted printing; as trailing trivia they are printed in
EndNode. Moving the marker to thebody's leading trivia would not work either - the auto-property transform drops the body and
would take the marker with it - so the accessor itself carries the init-only fact now and the
printer writes the marker next to the keyword. The flag is
[ExcludeFromMatch], because apattern written for a setter has to keep matching init-only setters.
Verified against
ilspycmdbuilt fromrelease/10.1: identical output again. Covered by a newUglyfixture that decompiles with C# 8 settings (red before, green after); the rest ofICSharpCode.Decompiler.Testsstays green (3333 passed, roundtrip excluded).🤖 Generated with Claude Code