Skip to content

Reject an accessorless property or unknown operator kind before writing anything [patch] - #140

Open
matt-edmondson wants to merge 1 commit into
mainfrom
claude/issue-128-validate-property-before-writing
Open

matt-edmondson wants to merge 1 commit into
mainfrom
claude/issue-128-validate-property-before-writing

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #128

What changed

  • PropertyTemplate.WriteTo now checks for "no getter, no setter, no expression body" before it calls base.WriteTo. Before this change, the doc comment, attributes, modifiers and Type Name were already in the buffer when the InvalidOperationException fired. Inside a class, the scope then closed the unfinished line as public int Foo}.
  • I rewrote the <remarks>, which still described the old behaviour where a property with no accessors was "terminated with a semicolon". I also added an <exception> entry for the throw.
  • OperatorTemplate.WriteTo now works out its signature, including the unknown-kind throw, before AddTemplate writes anything. The issue pointed out this case as having the same pattern.
  • AccessorTemplate already throws for an unknown kind before writing, so it is unchanged.

Tests

  • Two new tests, TemplateTests.ARejectedPropertyWritesNothing and TemplateTests.AnOperatorOfUnknownKindWritesNothing. Each one catches the exception and asserts that the CodeBlocker output is unchanged.
  • With the template changes reverted, both tests fail.
  • With the changes in place, the full suite passes (219/219, net10.0).

🤖 Generated with Claude Code

https://claude.ai/code/session_014h6btvAuM1Ew7cCFSpuFWc


Generated by Claude Code

…ng anything [patch]

PropertyTemplate.WriteTo wrote the doc comment, attributes, modifiers and
"Type Name" before checking that the property had an accessor or an
expression body, so the throw left an unfinished declaration in the
buffer; inside a class the scope then closed it as "public int Foo}".
OperatorTemplate did the same for an out-of-range Kind. Both now validate
first, so a caller that catches the exception can keep using the
CodeBlocker. The PropertyTemplate.WriteTo remarks, which still described
the old "terminated with a semicolon" behaviour, now describe the throw.

Fixes #128

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014h6btvAuM1Ew7cCFSpuFWc
@sonarqubecloud

Copy link
Copy Markdown

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.

PropertyTemplate with no accessors writes half its declaration before throwing, leaving public int Foo} in the output

2 participants