dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

Different behaviour of Android VM and Chrome (ddc) when implementing own iterable class #48306

Open Surio89 opened 2 years ago

Surio89 commented 2 years ago

Hi,

i created my own iterable class:

import 'package:fast_immutable_collections/fast_immutable_collections.dart';

class MyIter with FromIterableIListMixin<String> implements Iterable<String>{

  MyIter([Iterable<String> strings]) : _strings = IList(strings);

  final IList<String> _strings;

  @override
  IList<String> get iter => _strings;
}

if i use this class inside a for loop e.g.:

for (final String letter in _myIter){ string += letter; }

this iterable works well on android emulator but if i use chrome it throws:

"TypeError: this[_myIter] is not iterable"

only if i write: for (final String letter in _myIter.iter){ string += letter; }

it works. Did i do something wrong or is this a bug?

Dart Version 2.16.0. Windows Chrome Flutter 2.10.0

sigmundch commented 2 years ago

Based on the error, I believe this may be from DDC instead of dart2js.

@Surio89 - to confirm, does it fail when running in debug mode, but work if you run with flutter run -d chrome --profile or --release?

lrhn commented 2 years ago

Looks like a bug. The FromIterableIListMixin contains an Iterator<T> get iterator => iter.iterator; and you implement Iterable<String>, so it should work.

Surio89 commented 2 years ago

yes thats right only happens in debug mode not in --release