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 should give compile error for WhereIterables #40708

Closed
shinayser opened this issue Feb 20, 2020 · 1 comment
Closed

Dart should give compile error for WhereIterables #40708

shinayser opened this issue Feb 20, 2020 · 1 comment

Comments

@shinayser
Copy link

shinayser commented Feb 20, 2020

This happens VERY OFTEN with Flutter developers.

Check this simple code:

void main(List<String> arguments) async {
  var aList = <int>[1, 2, 3];

  aList = aList.where((element) => element.isEven);

  print(aList);
}

It compiles properly but gives runtime error:

type 'WhereIterable<int>' is not a subtype of type 'List<int>'
#0      main (file:///C:/Users/shina/Desenvolvimento/dart_projects/tests_dart/example/main.dart:31:3)
#1      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Well, if "where" doesn't return an List, why do the compiler let it be assigned to a List<int>?
It would save us tons of hours of developemnt trying to debug that.

@shinayser
Copy link
Author

It seems that this will be fixed on NNBD release.
Source: dart-lang/language#192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant