Repository navigation
fix: leave out a braced-list member initialiser that has no value [patch] - #173
Merged
Merged
Conversation
…tch] A MemberInitialiser's value may be null, which is how the graph editor holds one between adding it and filling it in. Every braced-list writer fell back to `new VariableReference(string.Empty)` for a null value, and that constructor throws on an empty name, so all seven generators threw ArgumentException as soon as the preview saw one. LanguageGeneratorBase.WrittenElements now gives the elements of a list without its unfilled member initialisers. The C#, Python and JavaScript list writers and the shared WriteElementList (C, C++, Go, Rust) write those elements. The list's shape (designated, keyword, object literal) is still decided by every argument, so a list whose only element is unfilled comes out as that language's empty designated list. Fixes #112 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017USYdQkEy3VLP48Dd4JadP
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
new MemberInitialiser("x")has a null value. That is legal, and the graph editor holds exactly this between adding a member initialiser and filling it in. Every braced-list writer fell back tonew VariableReference(string.Empty)for a null value, and that constructor throws on an empty name. So all seven generators threwArgumentException: Name cannot be null or whitespace, and the preview broke mid-edit.Following the triage note, the element is skipped:
LanguageGeneratorBase.WrittenElements(construction)returns the list's elements without anyMemberInitialiser { Value: null }.StandardLanguageGenerator.WriteElementList/WriteStackedList(C, C++, Go, Rust),CSharpGenerator.WriteBracedList,PythonGenerator.WriteLiteral/WriteArgumentsandJavaScriptGenerator.WriteLiteralnow write those elements.?? new VariableReference(string.Empty)fallbacks could no longer be reached and are removed.Point{}in Go,new Point { }in C#,{}in Python.The same fix also covers the Go, Rust and C constructor bodies that route initialisers through these list writers.
Example,
Point { unfilled = <none>, y = 2 }:Point p = { .y = 2 };Point p = Point{ .y = 2 };Point p = new Point { y = 2 };var p Point = Point{y: 2}let mut p: Point = Point { y: 2 };p = Point(y=2)let p = new Point({ y: 2 });Out of scope, possible follow-up: the Python and JavaScript constructor initialiser paths (
WriteInitialiserAssignments) don't throw. On a null value they writeself.x =/this.x = ;instead.Tests
UnfilledMemberInitialiserTests, run against all 7 generators:UnfilledMember_IsLeftOut: the unfilled member is left out and its filled sibling is still written.OnlyElementUnfilled_IsAnEmptyList: a typeless list whose only element is unfilled.main, all 14 cases fail withArgumentException: Name cannot be null or whitespace. With this change they pass.Coder.Testsuite: 1085 passed, 0 failed.Fixes #112
🤖 Generated with Claude Code
https://claude.ai/code/session_017USYdQkEy3VLP48Dd4JadP
Generated by Claude Code