Skip to content

is! operator with || #36982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tlserver opened this issue May 16, 2019 · 1 comment
Closed

is! operator with || #36982

tlserver opened this issue May 16, 2019 · 1 comment
Labels
closed-as-intended Closed as the reported issue is expected behavior closed-duplicate Closed in favor of an existing report

Comments

@tlserver
Copy link

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"

@lrhn
Copy link
Member

lrhn commented May 16, 2019

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).

@lrhn lrhn added the closed-as-intended Closed as the reported issue is expected behavior label May 16, 2019
@lrhn lrhn closed this as completed May 16, 2019
@lrhn lrhn added the closed-duplicate Closed in favor of an existing report label May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

2 participants