Skip to content

MemberInitialiser and ConstructionExpression have no editable fields, so their name and type cannot be set from the editor #48

Description

@matt-edmondson

What happens

AstFields has no case for MemberInitialiser or ConstructionExpression. Both fall through to the _ => [] default in OfExpression (Coder.Graph/AstFields.cs:298), and TryWrite has no case for either, so it falls through to _ => false (Coder.Graph/AstFields.cs:443).

The consequence is that the inspector draws no rows at all for these two nodes, and the two scalar properties they own are unreachable:

  • MemberInitialiser.Name (Coder/Ast/MemberInitialiser.cs:40) — which member is being initialised
  • ConstructionExpression.Type (Coder/Ast/ConstructionExpression.cs:34) — the type being constructed

Both nodes are otherwise fully wired: AstSchema gives them slots and handles their children (Coder.Graph/AstSchema.cs:56-57, 88, 105, 171, 175, 260, 313, 366), and the YAML serializer round-trips both. So a document containing a constructor with an initialiser list, or any new Foo(...) expression, opens in the graph editor with nodes whose most important property is visible in the generated source and in the YAML but cannot be read or changed in the inspector.

Why it is a defect rather than a design choice

Every other node with a TypeReference property exposes it as a Text field carrying Type?.ToString(), relying on TypeReference.Parse/ToString being inverses:

  • FieldDeclaration.TypeAstFields.cs:181
  • ClassDeclaration.BaseTypeAstFields.cs:190
  • EnumDeclaration.UnderlyingTypeAstFields.cs:158
  • UsingAlias.AliasedTypeAstFields.cs:177
  • Parameter.TypeAstFields.cs:237
  • FunctionDeclaration.ReturnTypeAstFields.cs:215

ConstructionExpression.Type is the same shape and was simply not added. MemberInitialiser.Name is the same shape as every other Name text field.

Both node types were introduced in the 2026-09-10 run of AST work (699d4c6, e2f18b4), which added them to the AST, the schema, the serializer and all four generators — the inspector is the one projection that was missed.

Suggested fix

Add the two cases to OfExpression and the matching cases to TryWrite, following the existing pattern:

MemberInitialiser initialiser =>
[
    new("Name", AstFieldKind.Text, initialiser.Name ?? string.Empty),
],

ConstructionExpression construction =>
[
    new("Type", AstFieldKind.Text, construction.Type?.ToString() ?? string.Empty),
],

with the corresponding (MemberInitialiser initialiser, "Name") and (ConstructionExpression construction, "Type") write cases parsing back through TypeReference.Parse the way FieldDeclaration's does.

Rationale

Coder.Graph's stated contract is that the AST is the document and the graph is a view of it. A node the graph can hold, the schema can describe and the serializer can persist, but the inspector cannot edit, breaks that contract in the one direction the editor exists for. A user can construct these nodes by opening a file that contains them but then has to leave the editor and hand-edit YAML to change what type is constructed.

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 working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions