-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed as not planned
Closed as not planned
Copy link
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).language-strong-mode-polish
Description
#29547 proposes extending strong mode impossible cast warnings to explicit casts as well as implicit casts. For implicit casts, we are at least guaranteed that the types are subtype related, but for explicit casts we allow casts between non-subtype related classes, since there may be a type somewhere which implements both. However, if either class is final and they are not subtype related, then the only way the cast can succeed is if the value is null, which is highly unlikely to be what the user intended. We should consider taking this into account and issuing an error.
void test() {
int x = 3;
bool y = (x as bool); // Make this an error
}Metadata
Metadata
Assignees
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).language-strong-mode-polish