Skip to content

casting json result to List<List<String>> #48686

Closed
@drpond1

Description

@drpond1

Using IntelliJ CE for a web app I have the following concern. debugging with Dart 2.16

I decode an object with json and then cast it to a List<List<String>> meta
Later, I try
for (List<String> list in meta) {...

This compiles but produces a runtime error of
List<dynamic> is not a List<String>

The type in the debugger is cast._new (I think) and the item
looks like a List<String>.

It seems to me that this is not a great behavior. I think the runtime
ought to know that this is ok, but that further runtime checks will
need to be done when the list in the for loop is read.

If this is not going to be allowed at runtime, then I think the type of meta should be
a compile time syntax error.
Some way of specifying List<List<cast.String>> might be an alternative, although List<List<dynamic>> is ok.

If needed, I can produce and test a simple example to duplicate the behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions