You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class A {
}
class B extends A {
int f;
B(this.f);
}
main() {
A b = B(1);
print(b is B && b.f == 1); // true
// apply De Morgan's laws
print(b is! B || b.f != 1); // expecting false but actually Error: The getter 'f' isn't defined for the class 'A'.
}
Is it possible that making Dart compiler think that b is B instead of A in the second case? b is always B when b is! B === false.
Dart VM version: 2.3.0 (Fri May 3 10:32:31 2019 +0200) on "windows_x64"
The text was updated successfully, but these errors were encountered:
Dart's type promotion is still very simple.
It only prmoteos on the positive branch of x is T tests, not on anything else (including not on the negative branches of x is! T).
We pla ton improve this in the future, no later than when introducing non-nullable types (becuse if (x != null) .... definitely should promote x` to non-nullable). We are tracking this in the language repository; dart-lang/language#81 .
For now, you'll just have to De Morgan yourself back to positive is tests when you need promotion.
(So, behaviior is intended, and as a request for improvement, I'm deferring to the language repo issue).
Is it possible that making Dart compiler think that
b
isB
instead ofA
in the second case?b
is alwaysB
whenb is! B === false
.Dart VM version: 2.3.0 (Fri May 3 10:32:31 2019 +0200) on "windows_x64"
The text was updated successfully, but these errors were encountered: