Skip to content

Print the init-only marker after the set keyword again - #4001

Open
siegfriedpammer wants to merge 1 commit into
masterfrom
fix/init-accessor-comment
Open

Print the init-only marker after the set keyword again#4001
siegfriedpammer wants to merge 1 commit into
masterfrom
fix/init-accessor-comment

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

When init accessors are unavailable (e.g. -lv CSharp8_0, or the setting turned off), an
init-only setter decompiles as set plus an /*init*/ marker. The marker used to sit right
after the keyword; since the slot AST migration it lands after the accessor body:

// 10.1                                     // master
public int Auto { get; set/*init*/; }       public int Auto { get; set; /*init*/}
set/*init*/                                 set
{                                           {
    backing = value;                            backing = value;
}                                           }
                                            /*init*/}

Comments used to be child nodes that InsertSpecialsDecorator flushed when the next node
started printing; as trailing trivia they are printed in EndNode. Moving the marker to the
body'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 a
pattern written for a setter has to keep matching init-only setters.

Verified against ilspycmd built from release/10.1: identical output again. Covered by a new
Ugly fixture that decompiles with C# 8 settings (red before, green after); the rest of
ICSharpCode.Decompiler.Tests stays green (3333 passed, roundtrip excluded).

🤖 Generated with Claude Code

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant