Skip to content

Write a typeless member list as new() in C# and a struct literal in Rust [patch] - #478

Merged
matt-edmondson merged 6 commits into
mainfrom
fix/typeless-designated-list-473
Nov 11, 2026
Merged

matt-edmondson merged 6 commits into
mainfrom
fix/typeless-designated-list-473

Conversation

@matt-edmondson

@matt-edmondson matt-edmondson commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A typeless ConstructionExpression whose arguments are MemberInitialisers is a designated initialiser for a declaration that has already said its type. C, C++ and Go already got it right. C# and Rust didn't:

Target Before After
C# Point p = { x = 1, y = 2 }; (CS0622, CS0103) Point p = new() { x = 1, y = 2 };
Rust let mut p: Point = [ x: 1, y: 2 ]; (syntax error) let mut p: Point = Point { x: 1, y: 2 };

Fixes #473

Tests

  • TypelessDesignatedListTests.TypelessDesignatedLists_Compile covers a local and a field initialiser of a Point struct. It is compiled with dotnet build, alongside a driver that reads both.
  • TypelessDesignatedListTests.TypelessDesignatedLists_CompileAndRun compiles the same AST with rustc and runs it. The run checks that both the local and the field hold the values they were given.
  • I checked both tests against the old code: they failed with the generator changes stashed and pass with them.
  • The full suite passes: 1758 of 1758.
  • The tests live in their own file, Coder.Test/Languages/TypelessDesignatedListTests.cs, rather than at the end of the shared C# and Rust compile-test classes, where every newly merged test collided with them.

Notes


Generated by Claude Code

…ust [patch]

A ConstructionExpression with no type whose arguments name members is a
designated initialiser for a declaration that has said its type. C# wrote
it as bare braces, `Point p = { x = 1, y = 2 };`, which C# takes only as
an array initialiser (CS0622), and Rust wrote `[ x: 1, y: 2 ]`, which is
not Rust.

C# now writes a target-typed `new() { x = 1, y = 2 }`. Rust writes the
receiving type's struct literal, `Point { x: 1, y: 2 }`, wherever a
declared type receives the value: a local, a return, and a field's
starting value in a constructor. The Python/JS criterion is left to #335.

Fixes #473

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ef43959 into main Nov 11, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the fix/typeless-designated-list-473 branch November 11, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants