Skip to content

Closure parameter annotation with a generic type parses as its argument: (v: Vec[i32]) => v.len() types v as i32 #1402

Closed

Description

@ehartford

Spec: §9.3 Closures (parameters may be annotated; (v: &W) => v.n with a non-generic type works).

fn main:
    var xs: Vec[i32] = Vec.new()
    xs.push(1)
    let f = (v: &Vec[i32]) => v.len()
    print(f(&xs))

Actual (installed v0.15.2.1, main dd786a4 stage1): error: unknown method 'len' for type 'i32' at v.len(). The same for (v: Vec[i32]) =>. The rendered closure in a follow-on diagnostic reads |v: i32|: the annotation keeps only the bracketed type argument.

Expected: v: &Vec[i32], prints 1.

A non-generic annotation (type W { n: i32 }, (v: &W) => v.n) is typed correctly.

Found while writing the #1379 fixture (an explicitly typed Option.filter predicate). Workaround used there: the typed-parameter cell uses a non-generic payload ((q: &P) => ...).

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