-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
closure type isn't inferred properly when a function returns a named closure #5983
Comments
Reproduced with 2ff6b29 . Nominating for milestone 5, production-ready. (Note that you have to comment out the |
@catamorphism there's been some churn with closures. I got as far as: 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;
}
fn main() {} trying to reproduce, which gives:
Is that the right error? |
accepted for backwards-compatible milestone |
This will continue to be relevant even when |
Also see #2202 (the larger bug) |
Thinking more about this: the case I was thinking of is wanting to use |
@nikomatsakis Do we want |
@pcwalton it can be pretty useful -- anyway even if we don't let
Shouldn't be too hard to make this infer properly, rather than based on the expected type, if there were a moment to spare on such trivialities. Anyway, this feels like it's not a 1.0 thing, improving inference can only make more code work etc etc. It can't do any worse than it does today. |
Nominated. I'm not sure if this issue should remain open, but it should not be "P-backcompat-lang". As @nikomatsakis says above:
|
Assigning P-low, not 1.0 milestone. |
actually, closing as unactionable since the example is so out of date as to unhelpful |
On IRC, jc-denton pointed out the following bug (original example at http://codepad.org/RFICaojj ):
This yields a type error because
fib
's type is inferred to&fn(int) -> int
. If you change the declaration offib
to have the explicit type@fn(int) -> int
, it compiles.Possibly related to #4929
The text was updated successfully, but these errors were encountered: