You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PropertyTemplate with no accessors writes half its declaration before throwing, leaving public int Foo} in the output #128
PropertyTemplate.WriteTo (CodeBlocker/Templates/PropertyTemplate.cs:47-67) calls base.WriteTo(codeBlocker) first, which writes the doc comment, attributes, modifiers and Type Name. Only afterwards does it check Getter is null && Setter is null and throw InvalidOperationException.
So by the time the exception fires, a partial declaration is already in the buffer. When the property is written from inside a ClassTemplate, the using Scope in ClassTemplate.WriteBodyTo (ClassTemplate.cs:123) disposes during the unwind and appends } onto the unfinished line.
Failure scenario
A class with a field int a; and a property { Name = "Foo", Type = "int", Keywords = { "public" } } with no getter, setter or expression body:
AddClass throws InvalidOperationException (as intended), but
the CodeBlocker buffer now holds:
public class C
{
int a;
public int Foo}
A caller that catches the exception and keeps using the same CodeBlocker (e.g. a generator that reports the bad member and moves on) emits source that doesn't compile. Throwing is fine; corrupting the output first isn't.
The <remarks> on WriteTo also still says "A property with no accessors at all is declared and terminated with a semicolon", which no longer matches the throw.
Suggested fix
Move the no-accessor validation (the Getter is null && Setter is null / no ExpressionBodyFactory check) to the top of WriteTo, before base.WriteTo, so nothing is written when it fails.
Update the <remarks> to describe the throw.
Add a test: catch the exception and assert the CodeBlocker output is unchanged.
Same pattern, lower impact (only reachable via out-of-range enum casts): the unknown-kind throws in OperatorTemplate.cs (~line 49) and AccessorTemplate.cs (~line 103) also fire after writing. Validating those up front too would be consistent.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
CodeBlocker. The throw itself is intended.Templates/PropertyTemplate.WriteTo, and the same pattern inOperatorTemplateandAccessorTemplate).Generated by Claude Code