Skip to content

Soundness issue with generator element type #53052

Open
@eernstg

Description

@eernstg

Thanks to @lrhn for spotting this issue and reporting it here.

The specification of the element type of a generator has just been updated accordingly, cf. dart-lang/language#3218.

The old rule gave rise to a soundness issue:

import 'dart:async';

FutureOr<Iterable<int>> f() sync* {
  yield 'Hello!' as dynamic;
}

void main() {
  var iterable = f();
  if (iterable is Future<Object?>) return;
  int i = iterable.first;
  print(i); // 'Hello!' is not an `int`.
}

The main idea in the correction is that the element type of a generator function uses a reduction step where the given return type is simplified to an Iterable<T> for some T (for a sync* function body) or a Stream<T> for some T (for an async* body), and the element type is then extracted from that Iterable<T> / Stream<T>.

Subtasks:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-metaCross-cutting, high-level issues (for tracking many other implementation issues, ...).implementationTrack the implementation of a specific feature (use on area-meta issue, not issues for each tool)soundness

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions