Skip to content

I wish we had --no-dynamic-calls as a lint #57703

Closed
dart-archive/linter
#2417
@matanlurey

Description

@matanlurey

Filing under "please lets fix this in Dart 2.1+".

Migrating internal code to Dart2, I hit the following fun error case:

class Link {
  static Link parse(Map<String, dynamic> linkData) {
    var userIds = linkData['userIds'].map((id) => int.parse(id));
     return new Link(userIds: userIds.toList());
  }

  final List<int> userIds;
  const Link({this.userIds});
}

... throws ...

type 'List<dynamic>' is not a subtype of type 'List<int>'

Huh? Shouldn't this work:

  .map((id) => int.parse(id));

It turns out, no! .map is a dcall, because linkData['userIds'] is dynamic. DOH!

Would --no-implicit-dynamic fix this? It seems like its an "explicit dynamic" (the map is typed of having values of type dynamic explicitly). It sounds like we'd need something strong_er_, i.e .--no-dynamic-calls.

/cc @leafpetersen @lrhn

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions