Repository navigation
Refuse an expression body that writes no expression, before writing [patch] - #178
Conversation
…patch] An ExpressionBodyFactory, or an expression accessor's BodyFactory, that wrote nothing or only blank lines rendered `int P => ;` / `get => ;`, which never compiles. The expression is now rendered before the declaration, and an empty one throws InvalidOperationException with the CodeBlocker left unchanged, as a null factory already does. Fixes #175 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW4VgeC1VNAtTYhxCrm
# Conflicts: # CodeBlocker/Templates/PropertyTemplate.cs
|
I merged One gap remains. Main's container pre-check ( Update: the earlier red CI came from the Generated by Claude Code |
Main's empty-expression fallback is dropped: this branch refuses an empty expression before anything is written, so the branch can't be reached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
|



Fixes #175
What changed
WriteExpressionBodywrote the=>arrow and a bare;when the callback produced nothing. That gaveint P => ;andget => ;(CS1525).Validateonly caught a null factory.TemplateRendering.RenderExpressionrenders the expression into lines. If every line is blank, it throwsInvalidOperationException.WriteExpressionBodynow takes those pre-rendered lines and no longer has a "wrote nothing" branch.PropertyTemplate.WriteTorenders itsExpressionBodyFactoryand any expression accessors beforebase.WriteTo, so a rejection leaves theCodeBlockerunchanged. That includes the doc comment.AccessorTemplate.WriteTo(public) also renders the expression first. The new internal overload accepts the pre-rendered expression fromPropertyTemplate.ExpressionBodyFactory,AccessorTemplate.WriteTo,ValidateandPropertyTemplate.WriteTodocs now cover the empty-expression case.Rendering the expression first doesn't change the output, because
RenderFragmentdepends only on the indent string and the newline. The current indent doesn't matter.Tests
AnEmptyExpressionBodyStillTerminatesTheDeclarationasserted the brokenpublic int X => ;output. It is replaced byAnEmptyExpressionBodyIsRejectedBeforeAnythingIsWritten, which also checks that the doc comment isn't left behind.Getter = AccessorTemplate.Expression(_ => { })repro, and a standaloneAccessorTemplate.WriteTo. Each one asserts that the call throws and the buffer is unchanged.Related
#176 covers a different case: a callback that throws. This PR doesn't try to fix that one.
Generated by Claude Code