3 ms·
Silently inferring List[Any] is like a null reference. The error that you get told about is in a different place to where the problem that you need to fix is. I
by HolyHaddock 12y ago
Silently inferring List[Any] is like a null reference. The error that you get told about is in a different place to where the problem that you need to fix is. In this case, the static type system could have been more helpful.
There have been attempts to fix this - WartRemover specifically has a Wart for any uses of Any for example.
- kod 12y agoNo, a compile time error is nothing at all like a runtime null pointer exception. Given that the language supports subtype polymorphism, this is exactly how the type inference should work. Any is the narrowest available supertype. If you don't like it, there's a pretty simple fix: add an explicit type ascription, which you should be doing for the return values of any methods anyway.
- dllthomas 12y agoIt's like a null reference in that both increase the distance between the error and the report of failure, and both have a way of working correctly. The distinction between compile time failure and runtime failure is an important one, but not the only thing going on.