Skip to content

Clone a variable reference that has no name yet [patch] - #199

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/161-clone-empty-variable-reference
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/161-clone-empty-variable-reference

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #161

What changed

  • VariableReference.Clone() used to call the validating VariableReference(string) constructor, which throws on an empty name. An empty name is a normal state: new AssignmentStatement() starts with an unnamed target, and the YAML reader produces one when the name is missing. C, C++, Rust and Go clone the whole class before they write it, so a class with a property and an unfilled assignment threw ArgumentException out of generation. In the editor's preview pane, that took the application down. The clone now goes through the parameterless constructor and assigns Name.
  • New UnfilledNodeCloneTests:
    • a reflective test that builds every concrete AstNode type with its parameterless constructor and clones it
    • an empty-name round trip
    • the issue's repro (a class with a property and a new AssignmentStatement() in a method) generated for C, C++, Rust and Go

Not in this PR

The issue lists two optional items, which I left out to keep this PR to the root cause:

  • Validate() flagging an empty VariableReference
  • CoderEditorApp.Regenerate catching ArgumentException/InvalidOperationException

Verification

  • With the fix reverted, all 6 new tests fail. With it in place, they pass.
  • Full Coder.Test suite: 1106 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ACXyQBPWSqFJuF51Mx6FNh


Generated by Claude Code

VariableReference.Clone() went through the validating constructor, which
throws on the empty name a new AssignmentStatement's target or a YAML node
with no name holds. C, C++, Rust and Go clone the whole class before
writing it, so any class with a property and an unfilled assignment threw
out of generation, and crashed the editor's preview. Clone through the
parameterless constructor instead, and check every node type clones from
its parameterless constructor.

Fixes #161

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

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 85c5a9a into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/161-clone-empty-variable-reference branch October 9, 2026 08:13
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.

VariableReference.Clone() throws on an empty name, crashing C/C++/Rust/Go generation (and the editor preview) for any class with a property

1 participant