Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(907)

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1405143006: improve static type analysis for `await for` (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/rules.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 6ed5d4cb199d9d63b6540c727561df51c7ecb80a..b8a5d790e19c517a4295e06f66b106febf3acd15 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -254,6 +254,12 @@ class AnalysisContextFactory {
// TODO(brianwilkerson) This is missing the optional parameters.
MethodElementImpl listenMethod =
ElementFactory.methodElement('listen', returnType, parameterTypes);
+ (listenMethod.type as FunctionTypeImpl).typeArguments =
+ streamElement.type.typeArguments;
+ (parameterTypes[0] as FunctionTypeImpl).typeArguments =
+ streamElement.type.typeArguments;
+ (parameterTypes[0].element as FunctionElementImpl)
+ .enclosingElement = listenMethod;
streamElement.methods = <MethodElement>[listenMethod];
asyncUnit.types = <ClassElement>[
@@ -13112,6 +13118,39 @@ f(Stream<String> stream) async {
}
}
+ void test_forEach_async_inheritedStream() {
+ // From https://github.com/dart-lang/sdk/issues/24191, this ensures that
+ // `await for` works for types where the generic parameter doesn't
+ // correspond to the type of the Stream's data.
+ String code = r'''
+import 'dart:async';
+abstract class MyCustomStream<T> implements Stream<List<T>> {}
+f(MyCustomStream<String> stream) async {
+ await for (var e in stream) {
+ e;
+ }
+}''';
+ Source source = addSource(code);
+ LibraryElement library = resolve2(source);
+ assertNoErrors(source);
+ verify([source]);
+ CompilationUnit unit = resolveCompilationUnit(source, library);
+ InterfaceType listOfStringType =
+ typeProvider.listType.substitute4([typeProvider.stringType]);
+ // in the declaration
+ {
+ SimpleIdentifier identifier = EngineTestCase.findNode(
+ unit, code, "e in", (node) => node is SimpleIdentifier);
+ expect(identifier.propagatedType, equals(listOfStringType));
+ }
+ // in the loop body
+ {
+ SimpleIdentifier identifier = EngineTestCase.findNode(
+ unit, code, "e;", (node) => node is SimpleIdentifier);
+ expect(identifier.propagatedType, equals(listOfStringType));
+ }
+ }
+
void test_functionExpression_asInvocationArgument() {
String code = r'''
class MyMap<K, V> {
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/rules.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698