Skip to content

Generic call: a bracket literal takes no array parameter demand (f[T](xs: [T; 3]) called f([7, 8, 9]) cannot infer T) #2379

Closed

Description

@ehartford

On main, a bracket literal fills a concrete array parameter under demand but not a generic one:

fn f[T](xs: [T; 3]) -> T: xs[0]
fn main:
    print(f([7, 8, 9]))

Actual: cannot infer type parameter 'T' for this call; the argument's shape does not match the parameter type that mentions 'T'. The non-generic twin (fn f(xs: [i32; 3])) compiles and prints 7; naming the array first (let a: [i32; 3] = [7, 8, 9]; f(a)) also works.

Cause, from the #2311 work: check_call types the literal with no demand (List[isize], D113), then check_generic_call binds only from arg types via bind_type_params_from_type_expr, whose NK_TYPE_ARRAY case requires a TY_ARRAY argument. The fix shape: bind from the literal's syntax where the demand is an array type — element type from the literal's elements, lengths (D119 Amendment 1) from their counts — or type the literal under the template's array demand before binding. Found while writing behav_d119a1_array_length_generics, which uses named arrays until this lands.

Activity

  1. added a commit that references this issue on Oct 13, 2026
  2. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed on main (b050a01, PR #2587, stack #2588): one commit with the fixture test/behavior/behav_2379_array_param_from_bracket_literal.w, which failed before the fix and passes after; battery GREEN on the stack top 077d684 (669 s, pinned seed nightly-20261023-local-1).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions