Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Fix uses_dynamic_as_bottom errors #22

Merged
merged 2 commits into from
Jan 18, 2018

Conversation

srawlins
Copy link
Contributor

uses_dynamic_as_bottom is a new error in Dart 2.0. dart-lang/sdk#29630

These hints can be seen by using dartanalyzer.

Copy link
Contributor

@sigmundch sigmundch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sam!

//
// .addAll(elements['library'].values.cast<Map>().map(parseLibrary));
result.libraries.addAll(
(elements['library'] as Map<dynamic, Map>).values.map(parseLibrary));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these cast will fail at runtime.

These maps are created from json parsing, which I believe creates maps as Map<dynamic, dynamic> and lists as List<dynamic>

I'm guessing that changing this to Map<dynamic, dynamic> is equivalent to what we have today, correct? If so, I believe we have a few options:

  • option A: wrap the closure to avoid the fuzzy arrow (this has an implicit cast):
(elements['library'] as Map).values.map((l) => parseLibrary(l));
  • option B: same, but with the cast more explicit
(elements['library'] as Map).values.map((l) => parseLibrary(l as Map));
  • option C: make the functions take dynamic and cast the parameter at the callee:
parseLibrary(dynamic jsonArg) {
  Map json = jsonArg;
  ...
}

I prefer option A.

@srawlins
Copy link
Contributor Author

Updated with your suggestions, thanks @sigmundch !

@sigmundch sigmundch merged commit a126fbd into dart-archive:master Jan 18, 2018
@srawlins srawlins deleted the fix-dynamic-as-bottom branch January 18, 2018 20:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

3 participants