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

Hint when type of element in list literal does not match variable type in assignment statement #20297

Closed
danrubel opened this issue Jul 31, 2014 · 4 comments
Assignees
Labels
analyzer-warning Issues with the analyzer's Warning codes 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

@danrubel
Copy link

There is no warning here ...

   List<String> list = [ new SomeClass() ];

... but when I refactor it, the warning appears ...

   List<String> list = [];
   list.add(new SomeClass()); // <<< warning argument type 'SomeClass' not assignable to 'String'

It would be helpful if there was at least a hint in the former case so that I catch problem code earlier.

@bwilkerson
Copy link
Member

Added Analyzer-Hint label.

@DartBot
Copy link

DartBot commented Jul 31, 2014

This comment was originally written by @Emasoft


As already discussed, this should give in both cases an error, not a warning. Otherwise there would be no type checking at all.

@DartBot
Copy link

DartBot commented Jul 31, 2014

This comment was originally written by @Emasoft


This is a serious issue, that can make or break the adoption of Dart in large projects. Allowing an int or any other type to be added to a string list without throwing an error is a recipe for a disaster. At the very least an explicit cast should be required.
Related to:
https://code.google.com/p/dart/issues/detail?id=20108
https://code.google.com/p/dart/issues/detail?id=20102

@danrubel danrubel added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Jul 31, 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 Mar 1, 2016
@srawlins
Copy link
Member

srawlins commented Apr 20, 2016

This hint exists in Strong mode. https://dartpad.dartlang.org/63e755de5d8d5afe4fb8b5b1d65c4dc3

warning: The element type 'int' cannot be assigned to the list type 'String'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes 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