Skip to content

Commit

Permalink
Band-aid fix for issue #24191.
Browse files Browse the repository at this point in the history
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.

[email protected]

Review URL: https://codereview.chromium.org//1307353002 .
  • Loading branch information
stereotype441 authored and whesse committed Aug 25, 2015
1 parent 1656d7f commit b4fa68e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11227,7 +11227,11 @@ class ResolverVisitor extends ScopedVisitor {
return null;
}
DartType eventType = onDataParameters[0].type;
if (eventType.element == streamType.typeParameters[0]) {
// TODO(paulberry): checking that typeParameters.isNotEmpty is a
// band-aid fix for dartbug.com/24191. Figure out what the correct
// logic should be.
if (streamType.typeParameters.isNotEmpty &&
eventType.element == streamType.typeParameters[0]) {
return streamType.typeArguments[0];
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/test/generated/non_error_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,22 @@ main() {
verify([source]);
}

void test_issue_24191() {
Source source = addSource('''
import 'dart:async';
class S extends Stream {}
f(S s) async {
await for (var v in s) {
print(v);
}
}
''');
computeLibrarySourceErrors(source);
assertNoErrors(source);
verify([source]);
}

void test_listElementTypeNotAssignable() {
Source source = addSource(r'''
var v1 = <int> [42];
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/test/generated/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ class AnalysisContextFactory {
// Stream
ClassElementImpl streamElement =
ElementFactory.classElement2("Stream", ["T"]);
streamElement.constructors = <ConstructorElement>[
ElementFactory.constructorElement2(streamElement, null)
];
DartType returnType = streamSubscriptionElement.type
.substitute4(streamElement.type.typeArguments);
List<DartType> parameterTypes = <DartType>[
Expand Down

0 comments on commit b4fa68e

Please sign in to comment.