Skip to content

Test element type of generator functions #2139

Closed
@eernstg

Description

@eernstg

We've noticed a soundness issue with the element type of generator functions, as mentioned in
dart-lang/language#3218.

@sgrekhov, it would be great if you could star that pull request, and write some language tests when it has been resolved!

In particular, we should cover the currently unsound behavior associated with examples given here, and we should cover the run-time types of objects returned by generator functions. We'd expect is Iterable<T> for a suitable T, or is Stream<T>. It's a bit less convenient to verify that the iterable/stream has an actual type argument which isn't too special (if we expect an Iterable<num> we shouldn't get an Iterable<int>), but it should be possible to build on this idea:

X combine<X>(X x, X _) => x;

void main() {
  List<num> xs = <int>[1];
  print('Combine for int:');
  (xs.reduce as dynamic)(combine<int>); // Type correct at run time. Ignore the type checker.
  print('Still alive. Combine for num:');
  xs.reduce(combine<num>);
  print('Not reached');
}

Metadata

Metadata

Assignees

Labels

type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions