Skip to content

Commit b4fa68e

Browse files
stereotype441whesse
authored andcommitted
Band-aid fix for issue #24191.
This is sufficient to avoid throwing an exception in the resolver, which in turn will prevent the analysis server from going into an infinite analysis loop. I'll work on a more complete fix (which infers the proper type in all cases) for the next release. R=brianwilkerson@google.com Review URL: https://codereview.chromium.org//1307353002 .
1 parent 1656d7f commit b4fa68e

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11227,7 +11227,11 @@ class ResolverVisitor extends ScopedVisitor {
1122711227
return null;
1122811228
}
1122911229
DartType eventType = onDataParameters[0].type;
11230-
if (eventType.element == streamType.typeParameters[0]) {
11230+
// TODO(paulberry): checking that typeParameters.isNotEmpty is a
11231+
// band-aid fix for dartbug.com/24191. Figure out what the correct
11232+
// logic should be.
11233+
if (streamType.typeParameters.isNotEmpty &&
11234+
eventType.element == streamType.typeParameters[0]) {
1123111235
return streamType.typeArguments[0];
1123211236
}
1123311237
}

pkg/analyzer/test/generated/non_error_resolver_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,22 @@ main() {
28982898
verify([source]);
28992899
}
29002900

2901+
void test_issue_24191() {
2902+
Source source = addSource('''
2903+
import 'dart:async';
2904+
2905+
class S extends Stream {}
2906+
f(S s) async {
2907+
await for (var v in s) {
2908+
print(v);
2909+
}
2910+
}
2911+
''');
2912+
computeLibrarySourceErrors(source);
2913+
assertNoErrors(source);
2914+
verify([source]);
2915+
}
2916+
29012917
void test_listElementTypeNotAssignable() {
29022918
Source source = addSource(r'''
29032919
var v1 = <int> [42];

pkg/analyzer/test/generated/resolver_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ class AnalysisContextFactory {
236236
// Stream
237237
ClassElementImpl streamElement =
238238
ElementFactory.classElement2("Stream", ["T"]);
239+
streamElement.constructors = <ConstructorElement>[
240+
ElementFactory.constructorElement2(streamElement, null)
241+
];
239242
DartType returnType = streamSubscriptionElement.type
240243
.substitute4(streamElement.type.typeArguments);
241244
List<DartType> parameterTypes = <DartType>[

0 commit comments

Comments
 (0)