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

type 'MappedListIterable<String, Project>' is not a subtype of type 'List<Project>' #34733

Open
akeating opened this Issue Oct 9, 2018 · 3 comments

Comments

Projects
None yet
6 participants
@akeating

akeating commented Oct 9, 2018

Moved over from flutter/flutter#22841. Although observed in a flutter project, @zoechi is able to reproduce as a pure dart issue.

$ flutter --version
Flutter 0.9.7-pre.76 • channel master • git@github.com:flutter/flutter.git
Framework • revision 6eac2d126c (15 hours ago) • 2018-10-08 19:22:20 -0400
Engine • revision 88facf4054
Tools • Dart 2.1.0-dev.6.0.flutter-c6254163dc

The original issue follows:

The following code appears to type-check but fails with flutter run:

final List<Project> projects = ['a', 'b', 'c'].map((name) {
    return Project(name);
});

and Project:

class Project {
  final String name;
  Project(this.name);
}

The resulting exception is:

I/flutter (13088): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY I/flutter (13088): The 
following assertion was thrown building Builder:
I/flutter (13088): type 'MappedListIterable<String, Project>' is not a 
subtype of type 'List<Project>'
$ flutter analyze
Analyzing flutter_app...                                         
No issues found! (ran in 1.9s)
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v0.9.7-pre.76, on Mac OS X 10.13.6 17G65, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
[✓] Android Studio (version 3.2)
[✓] VS Code (version 1.27.2)
[✓] Connected device (1 available)

• No issues found!

I have attached the default flutter project, modified to illustrate the problem
main.dart.zip

Expected: Since the code appears to type-check, the code should not fail at run-time.
Actual: The code fails at run-time.

I know that adding .toList() gets around this. The problem is that code that the ecosystem thinks is valid fails unexpectedly at run-time.

I'm thinking the code should fail to type-check in this case, but interested to hear of another perspective.

@zoechi

This comment has been minimized.

Show comment
Hide comment
@zoechi

zoechi Oct 9, 2018

Contributor

Moved from flutter/flutter#22841

I expected

analyzer:

  strong-mode:
    implicit-casts: false

to recognize that statically, but it seems not to.

Contributor

zoechi commented Oct 9, 2018

Moved from flutter/flutter#22841

I expected

analyzer:

  strong-mode:
    implicit-casts: false

to recognize that statically, but it seems not to.

@MichaelRFairhurst

This comment has been minimized.

Show comment
Hide comment
@MichaelRFairhurst

MichaelRFairhurst Oct 9, 2018

Contributor

Thanks for reporting!

Not sure what's going on, I haven't been able to get any implicit downcast warnings out of a list literal. Must be a regression.

I don't think we have good test coverage here unfortunately.

Contributor

MichaelRFairhurst commented Oct 9, 2018

Thanks for reporting!

Not sure what's going on, I haven't been able to get any implicit downcast warnings out of a list literal. Must be a regression.

I don't think we have good test coverage here unfortunately.

@bwilkerson bwilkerson added this to the Dart2.2 milestone Oct 10, 2018

@bwilkerson bwilkerson added the type-bug label Oct 10, 2018

@brianegan

This comment has been minimized.

Show comment
Hide comment
@brianegan

brianegan Oct 18, 2018

Gave a thumbs up as this is a bug I run into quite often, and it would be great to get static type checking working here!

brianegan commented Oct 18, 2018

Gave a thumbs up as this is a bug I run into quite often, and it would be great to get static type checking working here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment