Problems with closure type inference

Part of it's to avoid massive constraint systems, yes, but it's also to keep diagnostics from going completely off the rails (they are pretty bad in your examples, but they could be even worse), and to have a simpler model where a statement is type-checked in full before moving on to the next statement.

Other languages do have whole-function type inference, and you might wonder how they can get away with it. The answer is usually that those languages don't have overloading, which means that there aren't multiple ways to interpret function calls.

5 Likes