Skip to content

Block type-inference sometimes fails #912

Closed
@marijnh

Description

@marijnh

The follow code fails with

foo.rs:5:14: 5:18 error: the type of this value must be known in this context
foo.rs:5     find({|f| f.id == x}, arr);
                       ^~~~

If I move the += statement above the call to find, it typechecks. Maybe this is a fundamental limitation of our typechecker, but it looks like it could be worked around by delaying the error until all constraints in a function have been collected.

fn find<@T>(_f: block(T) -> bool, _v: [T]) {}

fn main() {
    let x = 10, arr = [];
    find({|f| f.id == x}, arr);
    arr += [{id: 20}]; // This assigns a type to arr
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions