Skip to content
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

Dart analyzer type inference with "is" type check #9666

Closed
DartBot opened this issue Apr 4, 2013 · 13 comments
Closed

Dart analyzer type inference with "is" type check #9666

DartBot opened this issue Apr 4, 2013 · 13 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Apr 4, 2013

This issue was originally filed by @bp74


What steps will reproduce the problem?

class foo {
}

class oneFoo extends foo {
  bool coolProperty = true;
}

class twoFoo extends foo {
  bool coolProperty = true;
}

void main() {
  foo f = getFoo();

  // case 1:
  if (f is oneFoo)
    if (f.coolProperty)
      print("works fine!");
  
  // case 2:
  if (f is oneFoo && f.coolProperty)
    print("analyzer warning :(");

  // case 3:
  if (f is oneFoo || f is twoFoo)
    if (f.coolProperty)
      print("analyzer warning :(");
}

foo getFoo() {
  return new oneFoo();
}

What is the expected output? What do you see instead?

The source above shows three cases, only case 1 works without an analyzer warning.
I think all those cases should be accepted by the analyzer as valid code, especially because case 1 is supported too.

case 2 and case 3 give the warning:
"coolProperty" is not a member of foo

What version of the product are you using? On what operating system?

Dart Editor version 0.1.2_r20908
Dart SDK version 0.1.2.0_r20908

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Apr 7, 2013

This comment was originally written by @bp74


Just tested with the new Dart Analyzer. The test "case 1" doesn't work too. So maybe it's better to write the code in another way anyway.

@bwilkerson
Copy link
Member

Just tested with the new Dart Analyzer.

The new analyzer does not yet have any type inferencing in it, but will handle "is" when type inferencing is added.


Set owner to @bwilkerson.
Added this to the M5 milestone.
Added Area-Analyzer, AnalysisEngine, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Apr 7, 2013

This comment was originally written by amouravski@google.com


Added Editor-AnalysisEngine label.

@bwilkerson
Copy link
Member

Case 1 is now working.


Removed Type-Defect, AnalysisEngine, Editor-AnalysisEngine labels.
Added Type-Enhancement label.

@kevmoo
Copy link
Member

kevmoo commented Jun 2, 2013

I think I'm hitting the same issue:

  SwapComponent _getSwap() {
    final Element element = this.query('[is=x-tabs] > [is=x-swap]');
    if(element != null) {
      if(element is SwapComponent) {
        // Warning here:
        // The return type "Element" is not a 'SwapComponent', as defined by the method '_getSwap'
        return element;
      } else if(element.xtag is SwapComponent) {
        return element.xtag;
      }
    }
    return null;
  }


Attachment:
[Screen Shot 2013-06-02 at 3.28.24 PM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-9666/comment-5/Screen Shot 2013-06-02 at 3.28.24 PM.png) (59.45 KB)

@bwilkerson
Copy link
Member

Removed this from the M5 milestone.
Added this to the M6 milestone.

@bwilkerson
Copy link
Member

Removed this from the M6 milestone.
Added this to the M7 milestone.

@jwren
Copy link
Member

jwren commented Sep 19, 2013

M7 -> M8


Removed this from the M7 milestone.
Added this to the M8 milestone.

@bwilkerson
Copy link
Member

Removed this from the M8 milestone.
Added this to the Later milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@DartBot DartBot added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Aug 4, 2014
@srawlins
Copy link
Member

srawlins commented Oct 9, 2015

Cases 1 and 2 are working now. So it's just the if (f is oneFoo || f is twoFoo) case. Can this be merged into a different issue? I think there's a similar one.

https://dartpad.dartlang.org/df971af508f1de386994

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@bwilkerson
Copy link
Member

Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants