Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Extension 'fields' cause a runtime error #378

Closed
vsmenon opened this issue Nov 2, 2015 · 2 comments
Closed

Extension 'fields' cause a runtime error #378

vsmenon opened this issue Nov 2, 2015 · 2 comments

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Nov 2, 2015

The following code triggers a runtime error in DDC:

import 'dart:collection';

class StringIterable extends IterableBase<String> {
  final Iterator<String> iterator = null;
}

main() => new StringIterable();

the problem is due to iterator being defined as a field (on the instance) as opposed to a getter/method (on the proto). We get a type error that iterator is an undefined property on defineExtensionMembers.

  class StringIterable extends collection.IterableBase$(core.String) {
    StringIterable() {
      this.iterator = null;
      super.IterableBase();
    }
  }
  dart.defineExtensionMembers(StringIterable, ['iterator']);
@vsmenon
Copy link
Contributor Author

vsmenon commented Nov 2, 2015

Per @jmesserly, we can fix this using our virtual field runtime helper.

@jmesserly
Copy link
Contributor

we should definitely fix this DDC bug.

However, it's probably worth sending a bug report to this package. Having "iterator" be a final field violates the contract of the "iterator" getter:
https://api.dartlang.org/1.12.2/dart-core/Iterable/iterator.html

Returns a new Iterator that allows iterating the elements of this Iterable.
[...]
Each time iterator is read, it returns a new iterator, which can be used to iterate through all the elements again. The iterators of the same iterable can be stepped through independently, but should return the same elements in the same order, as long as the underlying collection isn't changed.

@vsmenon vsmenon closed this as completed in 44741aa Dec 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants