-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closure inference is based on expected type #2190
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
Comments
There are two separate problems here. The first is that we do not push the expected type through records into their fields. The second is that our inference of the closure type is based purely on the expected type rather than generating some sort of variable that can later be unified. I think we should fix both (but probably the first one first). |
FWIW this actually demonstrates a second problem with closure inference - the nil in |
Don't think this has to do with records. The closure here infers as a
|
Actually the original bug may have been fixed since marijn did some work towards pushing expected types through records. I think the problem bblum points out is a separate but related issue. |
Indeed, what bblum points out (as brson pointed out earlier but I didn't understand it) is a problem that the "expected type" does not appear to be propagated to the expr in tail position in a record. |
sorry, tail position in a block |
This seems more extensive than just records - I'm running into trouble inferring closures inside of options. This works:
Now I try to put the closure in an option. It works if I just use the name
But if I use the bars syntax, it infers that as a
|
Give people an inch and they want a mile. :) Closure inference is broken in many ways, because it's a quick hack based on the expected type. I hope to replace with something more principled along the lines of what we do for integer literal inference though. |
(that commit has a case of the code in my above commit; tagged with a fixme. should be easy to get rid of the fixme after this bug.) |
Reproduced as of 3edccc3 |
I don't believe this is backwards incompatible, renominating. |
blocked on resolution of #6308 |
sub-bug of #6834 |
just a bug, removing milestone/nomination. |
Related to #6834 |
Visiting for triage. Sub-bug of #6834, therefore doesn't need to be on a milestone itself. |
Closure inference is gone, because there are only borrowed stack closures now. |
Not so. There are still things we might need to infer, such as closure bounds and so on. |
I updated the title to reflect the root problem. |
@nikomatsakis is this issue still relevant with all of the changes to closures? |
Not really. The current state roughly corresponds with what I described as the "ideal" scenario above, though I'd not call it ideal ideal. ;) |
😄 |
UPDATE: I updated the title to reflect the root problem. "Closure inference" refers to detailing the specifics of a closure type, such as its bounds and so forth. Ideally, only the argument types would derive from the expected type (with a fallback to fresh type variables).
original issue report follows:
The text was updated successfully, but these errors were encountered: