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_analsyer - add stricter type inference checks #9401

Closed
DartBot opened this issue Mar 24, 2013 · 4 comments
Closed

dart_analsyer - add stricter type inference checks #9401

DartBot opened this issue Mar 24, 2013 · 4 comments
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 Mar 24, 2013

This issue was originally filed by greg.low...@gmail.com


The flag "--type-checks-for-inferred-types" warns about:

    var q = new Queue<String>();
    q.iAmNotAMethodOnQueue();

But you don't get warnings for:

    var q = new Queue<String>();
    q = 42;

It would be nice too also warn about this second type of mistake, possibly behind another flag.

If you do really want to mix types in a variable, then label the field as dynamic, and no warnings will be emitted.

   dynamic qOrInt = new Queue<String>();
   qOrInt = 42

This is how c# mixes static type inference and dynamic types.

@bwilkerson
Copy link
Member

Added this to the Later milestone.
Removed Type-Defect label.
Added Type-Enhancement, Area-Analyzer, Triaged labels.

@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
@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
@srawlins
Copy link
Member

This is implemented as a strong mode warning.

$ cat 9401.dart
void main() {
  var q = new List<String>();
  q = 42;
}
$ dartanalyzer --strong 9401.dart
Analyzing [9401.dart]...
[error] Type check failed: 42 (int) is not of type List<String> (/Users/srawlins/code/9401.dart, line 3, col 7)
[warning] A value of type 'int' cannot be assigned to a variable of type 'List<String>' (/Users/srawlins/code/9401.dart, line 3, col 7)
[hint] The value of the local variable 'q' is not used (/Users/srawlins/code/9401.dart, line 2, col 7)
1 error, 1 warning and 1 hint found.

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

5 participants