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-gen] Fix lists containing atomic types #3210

Merged
merged 1 commit into from
May 8, 2023

Conversation

fondoger
Copy link
Contributor

@fondoger fondoger commented May 5, 2023

Before

Before will, this code will throw an error:
Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>'.

  factory SampleResponse.fromJson(Map<String, dynamic> m) {
    return SampleResponse(
      type: m['type'] ?? "",
      imageUrls: m['imageUrls'] ?? [],               ### Code can compile, but it will throw an error during run-time.
    );
  }

After

After fix, this code runs smoothly.

  factory SampleResponse.fromJson(Map<String, dynamic> m) {
    return SampleResponse(
      type: m['type'] ?? "",
      imageUrls: m['imageUrls']?.cast<String>() ?? [],
    );
  }

@kevwan kevwan force-pushed the fondoger/fix-atomic-list-types branch from 4c0d127 to d074b7e Compare May 6, 2023 06:30
@kevwan kevwan added this pull request to the merge queue May 8, 2023
Merged via the queue into zeromicro:master with commit c22bc1c May 8, 2023
6 of 7 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants