-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
In strong mode, this code gives no warnings but crashes at runtime:
Object o = 1;
void main() {
String s = o;
print(s.length);
}I understand this is a deliberate decision and can be "fixed" by using implicit-casts: false but it seems like a crazy default to me for something claiming to be strong. I can't find any info on why this was decided - most language don't seem to allow this and it doesn't seem to be something that people often claim about.
I think this may be discussed here; seems like it was related to the Flutter codebase:
I suspect that a lot of these will require changes to the Flutter code base, but we should make sure that the type system isn't making this unnecessarily hard.
We believe we can get rid of this warning and turn it into a lint that users can enable if they want help finding areas where runtime checks might fail for them.
I'd love this to be reconsidered, but at least, it'd be good to understand why it's this way. It seems like it's just gonna result in runtime errors that could easily be avoided. What's wrong with explicitly casting when required, or disabling this on your entire project if that's really a problem? It seems strange to weaken the type system because of one codebase (which would opt-out of this, or even insert explicit casts which would be an improvement IMO).