let bindings are typechecked using their inferred type not their (narrowed) annotated type
When a let binding produces a type error because of its annotation, the rest of the code is type-checked with the actual inferred type of the binding instead of the (possibly narrowed) annotated type. This potentially produces misleading follow-up type errors:
pub fn main() {
let x: String = 5 // type error: expected String, got Int
let y: Int = x // valid
let z: String = x // type error: expected String, got Int
}
I think the assignment to y should produce the type error here, not z. I would have expected one of the major benefits of adding explicit annotations to be to help the compiler produce better errors in exactly those situations. My assumption here of course is that if the user adds an explicit annotation, they want and expect that annotation to be assumed the correct type.
~ 💜
Sounds reasonable. Would this be a breaking change in any situations? I can't think of any myself.
The only thing we need to make sure is that variant inference is preserved. Other than that, it should only change error messages when the types don't line up