Skip to content

A nested or reassigned typeless designated list is still written bare: Go Line{a: {x: 1}}, C p = { .x = 7 }; and len({ .x = 9 }), Rust p = [ x: 7, y: 8 ]; don't compile #494

Open

Description

@matt-edmondson

What's wrong

#478 (fixing #473) gave a ConstructionExpression that has no type and only MemberInitialiser arguments its receiving type. It did this in C#, and in Rust for three positions: a local, a return and a constructor field. In every other position the list is still written bare, and the target languages reject it.

Repro

struct Point { int x, y }
struct Line { Point a, b }

int run() {
  Line l = { a = { x = 1, y = 2 }, b = { x = 3, y = 4 } };
  Point p = { x = 5, y = 6 };
  p = { x = 7, y = 8 };
  return len({ x = 9, y = 10 }) + p.x + l.b.y;
}
Target Generated Result
Go var l Line = Line{ a: {x: 1, y: 2}, ... } missing type in composite literal. Go only elides the type for slice, array and map elements, never for struct fields.
Go p = {x: 7, y: 8}, len({x: 9, y: 10}) syntax error: unexpected {
C p = { .x = 7, .y = 8 };, len({ .x = 9, .y = 10 }) gcc: expected expression before '{' token. These need the compound literal (Point){ .x = 7, .y = 8 }.
Rust p = [ x: 7, y: 8 ]; parse error
C#, C++ new() { … } / { .x = … } compile (checked with dotnet build and g++ -std=c++20)

Where in the code

  • Go: GenerateConstructionExpression (Coder/Languages/GoGenerator.cs:2162-2171) writes {…} with no type whenever Type is null. That includes a member's value inside a struct literal.
  • C: the list (CGenerator.cs:955, CFamilyGenerator.cs:274) is never written as a compound literal outside an initialiser.
  • Rust: WriteValue (RustGenerator.cs:1566-1581) is reached for a self. field assignment (:1665-1679) but not for an assignment to a local.

Related: #409 (open) covers non-designated typeless lists in Go and Rust returns, assignments and arguments, and overlaps with the Go assignment and argument cases here. This issue is the designated-list (MemberInitialiser) side, plus C and the nested Go struct-field case.

Acceptance criteria

  • Go: a nested designated list takes its member's declared type: Line{a: Point{x: 1, y: 2}}.
  • C: a typeless list used outside a declaration's initialiser (assignment, argument or return) is written (T){ … }.
  • Rust: an assignment to a local goes through WriteValue, as a self. field assignment already does.
  • The C, Go and Rust compile tests gain these cases.

Activity

  1. matt-edmondson commented on Nov 12, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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