Skip to content

closure type isn't inferred properly when a function returns a named closure #5983

@catamorphism

Description

@catamorphism

On IRC, jc-denton pointed out the following bug (original example at http://codepad.org/RFICaojj ):

fn memFib(n: int) -> @fn(int) -> int {
    let mut memo = @~[0, 1];
    let fib = |n: int| -> int {
        let mut result: int = - 1;
        if n < memo.len() as int {
            result = memo[n];
        } else {
            result = fib(n - 1) + fib(n - 2);
            memo.push(result);
        }
        return result;
    };
    return fib;
}

This yields a type error because fib's type is inferred to &fn(int) -> int. If you change the declaration of fib to have the explicit type @fn(int) -> int, it compiles.

Possibly related to #4929

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions