Skip to content

Wrong type inferred for closure when returned from function #4929

Closed
@veddan

Description

@veddan
fn make_adder(x: int) -> @fn(int) -> int { |y| x + y }

The above function gives a compile error:
mismatched types: expected @fn(int) -> int but found &fn(int) -> int (expected @ closure, found & closure)

If I change the expression syntax into an explicit return:

fn make_adder(x: int) -> @fn(int) -> int { return |y| x + y; }

the code compiler (and runs) without error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions