Skip to content

Rust writes a typeless braced list as an array where a Vec is expected (let xs: Vec<i32> = [1, 2]; E0308), and Go writes a bare return {1} #409

Open

Description

@matt-edmondson

What's wrong

A ConstructionExpression with no type is "the list alone, which initialises a declaration that has already said its type" (CLAUDE.md). Two targets get it wrong outside constant tables:

  • Rust: SpellCoreType spells an array type as Vec<T> (
    return type.IsArray ? $"Vec<{core}>" : core;
    ). But GenerateConstructionExpression always writes a typeless list as an array literal [ … ] (RustGenerator.cs L2313-L2317). Only the static/const table path wraps it as &[ … ] to match &[T]. So a local, a return value or an argument of array type gets an array where a Vec is expected.
  • Go: a typeless list is written bare as {…} (GoGenerator.cs L2076-L2080). A local declaration supplies the type prefix itself, but a return (GoGenerator.cs L1754-L1760, via the base class) does not.

Repro

  • int first() { int[] xs = {1, 2}; return 0; } → Rust let mut xs: Vec<i32> = [ 1, 2 ]; → rustc E0308 expected Vec<i32>, found [{integer}; 2]
  • int[] all() { return {1}; }:
    • Rust return [ 1 ]; → E0308
    • Go return {1} → syntax error: unexpected {, expected expression

Acceptance criteria

  • In Rust, a typeless list whose receiving type is Vec<T> (a local, return, assignment, argument or instance field default) is written vec[…]. Module statics keep &[…].
  • In Go, a typeless list in a return, assignment or argument gets the receiving type in front ([]int{1}), as a local declaration already does.
  • Cases are added to the Rust and Go compile tests.

Activity

  1. added
    bug
    on Oct 31, 2026
  2. matt-edmondson commented on Oct 31, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Medium. In Rust, an array-typed local, return or argument built from a typeless list fails with E0308. In Go, returning a typeless list is a syntax error. Both are common shapes, but they fail loudly at compile time.
    • Area: RustGenerator.GenerateConstructionExpression (the typeless-list branch, which writes [ … ] where SpellCoreType expects Vec<T>). GoGenerator.GenerateConstructionExpression and the return path, which need the receiving type in front of the list. Tests go in the Rust and Go compile tests.
    • Suggested assignment: Rust/Go generators owner.
    • Related: Go: narrower numbers in struct literals, constructor initialisers and typed list elements aren't converted (Acc{total: a} with int → int64), so the output doesn't compile #408 is the same kind of gap: a value in a Go composite or list literal isn't adapted to its receiving type. Both could share the "receiving type" plumbing.
    • Duplicates / in progress: No duplicate found. No open PR covers typeless list literals.

    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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions