Skip to content

Introduce intersection types in strong-mode analyzer? #26350

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
ochafik opened this issue Apr 27, 2016 · 5 comments
Closed

Introduce intersection types in strong-mode analyzer? #26350

ochafik opened this issue Apr 27, 2016 · 5 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@ochafik
Copy link
Contributor

ochafik commented Apr 27, 2016

This would allow precise analysis of the following (real-world) case:

if (entity is Observable && entity is Map) {
  takeMap(entity);
  //      ^
  // [WARNING] The argument type 'Observable' cannot be assigned to the parameter type 'Map'.
}

cc/ @leafpetersen

(of course, the workaround here is to pass entity as dynamic, but it just feels wrong)

@bwilkerson
Copy link
Member

Or reverse the order of the test:

if (entity is Map && entity is Observable) {

@ochafik
Copy link
Contributor Author

ochafik commented Apr 27, 2016

Sure, that as well (it does feel less wrong :-) ), although the general case would be:

if (entity is Observable && entity is Map) {
  takeMap(entity);
  takeObservable(entity);
}

@floitschG
Copy link
Contributor

This is something we would like to improve.
Similarly annoying:

if (o is! List) return null;
o[x];  // Not inferred to be of type List.

or

if (o.x is List) {
  o.x[0];  // Not inferred to be a List.
}

@ochafik
Copy link
Contributor Author

ochafik commented Apr 28, 2016

@floitschG +1, first example filed as #26195 for the record

@iposva-google iposva-google added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label May 6, 2016
@lrhn lrhn added the type-enhancement A request for a change that isn't a bug label Jun 25, 2018
@lrhn
Copy link
Member

lrhn commented Jun 25, 2018

Closing as duplicate of #25565 (enhanced type promotion).

@lrhn lrhn closed this as completed Jun 25, 2018
@lrhn lrhn added the closed-duplicate Closed in favor of an existing report label Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants