-
Notifications
You must be signed in to change notification settings - Fork 27
improve type promotion #274
Comments
one idea here: if we fixed #239, we could have the "strong mode option" let analyzer put their already-better propagated type into the static type instead. That would improve at least some of the cases above. |
Analyzer's propagated type isn't always better, but in those few places where it is (such as where we do some flow analysis) you could certainly make use of that information. |
Maybe the answer here is to do a "pattern matching" DEP rather than try and fix the many issues with type promotion... what concerns me about trying to fix it is we'd need to introduce several kinds of analysis (union types, tracking variable types across the control flow graph) to make the feature reliable. =\ |
(and ultimately, pattern matching is a better solution to the problem) |
Moved to dart-lang/sdk#25565 |
There are some cases where type promotion won't work. Found while investigating the state of #31.
NOTE: My current thought here is that we should file a DEP for pattern matching, rather than try and hack type promotion into something sensible. The feature as is seems to cause a lot of user confusion.
It roughly falls into a few buckets:
T
ofv
wasdynamic
, the testv is SomeType
won't promote. This leads to some suboptimal codegen in SDK (see strong mode should allow type promotion from dynamic dart-lang/sdk#25486)S
is not a subtype ofT
, the test won't promote. You'd have to track a union type.if (v is! S) return;
don't affect the type ofv
in the rest of the method body.assert(v is S);
and havev
be treated as S for the rest of the method. Sort of like an unchecked (in production mode) cast, similar toS v2 = v
but not requiring a second variable name to be introduced.T extends Event
, not promoting to a subtype of Event likeInputEvent
, see 'is' check in a trinary operator should do type promotion #327The text was updated successfully, but these errors were encountered: