-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Type inference depends on ordering #42333
Comments
This is a known limitation of the in-order type-checker. While inference flows freely, |
Thanks for the answer, which alas I do not fully understand. I took a look at the community resources, and there's a lot about a lot of subjects, but not much about how to intuit how the type-checker would be expected to behave. But I appreciate you letting me know that it is well understood and expected behaviour. |
@mulkieran What I mean is that the type-checker goes through the function in the order it was written. It knows Fields accesses and methods calls are simply not supported unless the type is already known. The information can come in various ways, even e.g. |
Closing as a known limitation, that there's little point in tracking in separate issues. |
This code ( https://is.gd/6jsqIt) gives the following compile error:
I believe that the type of the error should be known in the context, because the type of
things
is certainly known, and therefore the types of the elements yielded bythings.drain()
. Note that the error has to do with the publicly accessiblef1
field ofthing
, which should be know to bePathBuf
.I can eliminate the error by adding a type annotation of
Vec<Thing>
to the declaration ofthings
.I can also eliminate the error by swapping the positions of the
things.push
line and theif x == 2
block.These facts are true as of today for Stable, Beta, Nightly.
The text was updated successfully, but these errors were encountered: