Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soundness issue with generator element type #53052

Open
eernstg opened this issue Jul 27, 2023 · 1 comment
Open

Soundness issue with generator element type #53052

eernstg opened this issue Jul 27, 2023 · 1 comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) soundness

Comments

@eernstg
Copy link
Member

eernstg commented Jul 27, 2023

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:

@eernstg eernstg added area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). soundness implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) labels Jul 27, 2023
@chloestefantsova
Copy link
Contributor

Sorry, I accidentally closed this one instead of #53053. Reopened it again. Thanks for noticing, @eernstg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) soundness
Projects
None yet
Development

No branches or pull requests

2 participants