Skip to content

Every generator throws ArgumentException on a braced-list MemberInitialiser with no value (new MemberInitialiser("x")) #112

Description

@matt-edmondson

What's wrong

When a braced-list element's value is null, every generator falls back to designated.Value ?? new VariableReference(string.Empty):

  • Coder/Languages/StandardLanguageGenerator.cs:610 (C, C++, Go, Rust)
  • Coder/Languages/CSharpGenerator.cs:450
  • Coder/Languages/PythonGenerator.cs:241, :268
  • Coder/Languages/JavaScriptGenerator.cs:235

VariableReference(string) throws on an empty or whitespace name (Coder/Ast/VariableReference.cs:20), so this fallback always throws. A null value is legal: the constructor is MemberInitialiser(string name, Expression? value = null). The graph editor also produces one, because AstSchema.cs:654 accepts a MemberInitialiser as an element and its Value slot starts out empty. Constructor initialisers already guard against null (CppGenerator.cs:252 and CSharpGenerator.cs:680 check if (initialiser.Value is not null)). Only the braced-list paths crash.

Repro

ConstructionExpression pt = new("Point");
pt.Arguments.Add(new MemberInitialiser("x"));
generator.Generate(new VariableDeclaration { Name = "p", Type = "Point", InitialValue = pt });

Observed: all 7 generators throw ArgumentException: Name cannot be null or whitespace (Parameter 'name'). The stack runs from WriteListElement / WriteBracedList into VariableReference..ctor.

Why it matters

A user building a struct literal in the editor gets an exception from the preview as soon as they add a member initialiser, before they have filled in its value. A programmatic caller hits the same exception with a signature the API advertises as valid.

Suggested fix / acceptance criteria

  • Handle a null Value explicitly at each site, the same way the constructor-initialiser paths do. Either emit the member with the language's default value ({ .x = {} }, x = default, x: Default::default(), …) or skip the element.
  • Add a test that generates new MemberInitialiser("x") inside a ConstructionExpression with every generator, without throwing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreadyFully specified; implement as written

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions