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
An expression-body callback that writes nothing renders int P => ; / get => ; (CS1525), the output Validate says it prevents #175
When an ExpressionBodyFactory (or the BodyFactory of an AccessorTemplate.Expression) writes no non-blank lines, TemplateRendering writes the arrow anyway and then a bare semicolon (TemplateRendering.cs#L343-L348):
AccessorTemplate.Validate says it throws for the case that "would render as get => ;" (AccessorTemplate.cs#L115-L135). It only checks for a null BodyFactory, though, so #142's fix doesn't cover a factory that runs and writes nothing.
newPropertyTemplate{Name="P",Type="int",ExpressionBodyFactory= _ =>{}}.WriteTo(cb);// int P => ;newPropertyTemplate{Name="P",Type="int",Getter=AccessorTemplate.Expression(_ =>{})}.WriteTo(cb);// int P// {// get => ;// }
A callback that writes only blank lines, for example when joining an empty list of terms, gives the same result. Neither output compiles (CS1525, invalid expression term ;), and nothing tells the generator author.
Why it matters
Block bodies handle "wrote nothing" on purpose and render { }. An expression body has no valid empty form, so the library hands back code that can never compile. The failure only shows up later, as a compile error in the consumer's generated file, far from the template call that caused it.
Suggested fix / acceptance criteria
Render the expression into its fragment before writing the declaration. If it has no non-blank lines, throw InvalidOperationException and write nothing, matching the null-factory case.
Do the same for expression accessors, and extend the AccessorTemplate.Validate and PropertyTemplate.ExpressionBodyFactory docs to cover an empty expression.
Tests: both repros above throw, and leave the CodeBlocker buffer unchanged.
Activity