Fix error in type cast.#97778
Conversation
| startPaused: (json['startPaused'] as bool?)!, | ||
| dartFlags: (json['dartFlags'] as String?)!, | ||
| dartEntrypointArgs: ((json['dartEntrypointArgs'] as List<String>?)?.cast<String>())!, | ||
| dartEntrypointArgs: ((json['dartEntrypointArgs'] as List<dynamic>?)?.cast<String>())!, |
There was a problem hiding this comment.
I'm a little confused as to this fix:
Casting to List is an error when the original list is List.
even after this change, the object could still be a list. It doesn't seem like calling list.cast<T>() where list is already a List<T> does not seem to be an error. Also, the test you added still passes without this fix.
There was a problem hiding this comment.
Github removed everything between <> in my original comment, I meant to say "casting to List<String> is an error when the original list is List<dynamic>."
Updated the original description.
And I missed a step in the test, I've updated the test to convert it to JSON string, and parse the JSON into a Map<String, Object>, and then run DebuggingOptions.fromJson.
The object returned from json.decode is a List<dynamic>, and it is an error to cast that to List<String> directly. It should be casted by using (list as List<dynamic>).cast<String>()
PTAL, thanks
There was a problem hiding this comment.
Ahh, ok, that makes sense now :)
|
This pull request is not suitable for automatic merging in its current state.
|
Casting to
List<String>is an error when the original list isList<dynamic>.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.