Skip to content

Commit

Permalink
[cfe] Handle for-in on type variables in TypeEnvironment.forInElement…
Browse files Browse the repository at this point in the history
…Type

Closes #39565

Change-Id: I5b4c437879be0a97b306c5cc3579faac917d7e7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127162
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Dec 5, 2019
1 parent c1565a7 commit e4e3f3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/front_end/test/static_types/data/for_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,23 @@ customStreamIterator(StreamWithCustomIterator stream) async {
e;
}
}

void genericIterable<T extends Iterable<T>>(T x) {
/*current: T*/
for (var y in
/*cfe|dart2js.T*/
/*cfe:nnbd.T!*/
x) {
/*T*/ y;
}
}

void genericStream<T extends Stream<T>>(T x) async {
/*current: T*/
await for (var y in
/*cfe|dart2js.T*/
/*cfe:nnbd.T!*/
x) {
/*T*/ y;
}
}
5 changes: 5 additions & 0 deletions pkg/kernel/lib/type_environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ abstract class TypeEnvironment extends SubtypeTester {
DartType forInElementType(ForInStatement node, DartType iterableType) {
// TODO(johnniwinther): Update this to use the type of
// `iterable.iterator.current` if inference is updated accordingly.
while (iterableType is TypeParameterType) {
TypeParameterType typeParameterType = iterableType;
iterableType =
typeParameterType.promotedBound ?? typeParameterType.parameter.bound;
}
if (node.isAsync) {
InterfaceType type =
getTypeAsInstanceOf(iterableType, coreTypes.streamClass);
Expand Down

0 comments on commit e4e3f3f

Please sign in to comment.