Sdk: [].where not a list

Created on 14 Apr 2018  路  3Comments  路  Source: dart-lang/sdk

Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"

the code:

final List<int> list = [1,3,4];
final List<int> res = list.where((i) => true);

fails runtime:

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

method where:

Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test);

interface Iterable:

abstract class Iterable<E> {...}

expected behavior:

compile time error.

Most helpful comment

Yup, Iterable does not implement List.

You are looking for .where((i) => true).toList().

All 3 comments

Yup, Iterable does not implement List.

You are looking for .where((i) => true).toList().

I'm not looking for toList method. I'm looking for the API that doesn't fail runtime after it compiles

Then I recommend you 馃憤 this issue: https://github.com/dart-lang/sdk/issues/31410

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  3Comments

DartBot picture DartBot  路  3Comments

bergwerf picture bergwerf  路  3Comments

xster picture xster  路  3Comments

DartBot picture DartBot  路  3Comments