Type inference failure when accessing a value before its type is resolved
@jplatte It’s essentially the same phenomenon, but triggered in a different way.
@tczajka Your example is indeed much clearer.
Working case:
A has an unknown type → A = B → B has a known type → compiles successfully
Failing case:
A has an unknown type → access A.field → A = B → B has a known type → type inference fails
Even though the IDE (e.g. Rust Analyzer) resolves the type correctly, the compiler still reports a type inference error.
It seems that type inference loses track of the type if the value from A is accessed or manipulated before it is assigned to B.
This would be a welcome improvement.
I revised the post title and content (as well as the GitHub issue) so that the problem is no longer described as being specific to loops, but rather presented in a more general way.
Discussion in the ATmosphere