| OLD | NEW | 
|      1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file |      1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file | 
|      2 // for details. All rights reserved. Use of this source code is governed by a |      2 // for details. All rights reserved. Use of this source code is governed by a | 
|      3 // BSD-style license that can be found in the LICENSE file. |      3 // BSD-style license that can be found in the LICENSE file. | 
|      4  |      4  | 
|      5 library engine.resolver_test; |      5 library engine.resolver_test; | 
|      6  |      6  | 
|      7 import 'dart:collection'; |      7 import 'dart:collection'; | 
|      8  |      8  | 
|      9 import 'package:analyzer/src/context/context.dart' as newContext; |      9 import 'package:analyzer/src/context/context.dart' as newContext; | 
|     10 import 'package:analyzer/src/generated/ast.dart'; |     10 import 'package:analyzer/src/generated/ast.dart'; | 
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    247         .substitute4(streamElement.type.typeArguments); |    247         .substitute4(streamElement.type.typeArguments); | 
|    248     List<DartType> parameterTypes = <DartType>[ |    248     List<DartType> parameterTypes = <DartType>[ | 
|    249       ElementFactory |    249       ElementFactory | 
|    250           .functionElement3('onData', VoidTypeImpl.instance.element, |    250           .functionElement3('onData', VoidTypeImpl.instance.element, | 
|    251               <TypeDefiningElement>[streamElement.typeParameters[0]], null) |    251               <TypeDefiningElement>[streamElement.typeParameters[0]], null) | 
|    252           .type, |    252           .type, | 
|    253     ]; |    253     ]; | 
|    254     // TODO(brianwilkerson) This is missing the optional parameters. |    254     // TODO(brianwilkerson) This is missing the optional parameters. | 
|    255     MethodElementImpl listenMethod = |    255     MethodElementImpl listenMethod = | 
|    256         ElementFactory.methodElement('listen', returnType, parameterTypes); |    256         ElementFactory.methodElement('listen', returnType, parameterTypes); | 
 |    257     (listenMethod.type as FunctionTypeImpl).typeArguments = | 
 |    258         streamElement.type.typeArguments; | 
 |    259     (parameterTypes[0] as FunctionTypeImpl).typeArguments = | 
 |    260         streamElement.type.typeArguments; | 
 |    261     (parameterTypes[0].element as FunctionElementImpl) | 
 |    262         .enclosingElement = listenMethod; | 
|    257     streamElement.methods = <MethodElement>[listenMethod]; |    263     streamElement.methods = <MethodElement>[listenMethod]; | 
|    258  |    264  | 
|    259     asyncUnit.types = <ClassElement>[ |    265     asyncUnit.types = <ClassElement>[ | 
|    260       completerElement, |    266       completerElement, | 
|    261       futureElement, |    267       futureElement, | 
|    262       streamElement |    268       streamElement | 
|    263     ]; |    269     ]; | 
|    264     LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( |    270     LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | 
|    265         coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); |    271         coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); | 
|    266     asyncLibrary.definingCompilationUnit = asyncUnit; |    272     asyncLibrary.definingCompilationUnit = asyncUnit; | 
| (...skipping 12838 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  13105       expect(identifier.propagatedType, same(stringType)); |  13111       expect(identifier.propagatedType, same(stringType)); | 
|  13106     } |  13112     } | 
|  13107     // in the loop body |  13113     // in the loop body | 
|  13108     { |  13114     { | 
|  13109       SimpleIdentifier identifier = EngineTestCase.findNode( |  13115       SimpleIdentifier identifier = EngineTestCase.findNode( | 
|  13110           unit, code, "e;", (node) => node is SimpleIdentifier); |  13116           unit, code, "e;", (node) => node is SimpleIdentifier); | 
|  13111       expect(identifier.propagatedType, same(stringType)); |  13117       expect(identifier.propagatedType, same(stringType)); | 
|  13112     } |  13118     } | 
|  13113   } |  13119   } | 
|  13114  |  13120  | 
 |  13121   void test_forEach_async_inheritedStream() { | 
 |  13122     // From https://github.com/dart-lang/sdk/issues/24191, this ensures that | 
 |  13123     // `await for` works for types where the generic parameter doesn't | 
 |  13124     // correspond to the type of the Stream's data. | 
 |  13125     String code = r''' | 
 |  13126 import 'dart:async'; | 
 |  13127 abstract class MyCustomStream<T> implements Stream<List<T>> {} | 
 |  13128 f(MyCustomStream<String> stream) async { | 
 |  13129   await for (var e in stream) { | 
 |  13130     e; | 
 |  13131   } | 
 |  13132 }'''; | 
 |  13133     Source source = addSource(code); | 
 |  13134     LibraryElement library = resolve2(source); | 
 |  13135     assertNoErrors(source); | 
 |  13136     verify([source]); | 
 |  13137     CompilationUnit unit = resolveCompilationUnit(source, library); | 
 |  13138     InterfaceType listOfStringType = | 
 |  13139         typeProvider.listType.substitute4([typeProvider.stringType]); | 
 |  13140     // in the declaration | 
 |  13141     { | 
 |  13142       SimpleIdentifier identifier = EngineTestCase.findNode( | 
 |  13143           unit, code, "e in", (node) => node is SimpleIdentifier); | 
 |  13144       expect(identifier.propagatedType, equals(listOfStringType)); | 
 |  13145     } | 
 |  13146     // in the loop body | 
 |  13147     { | 
 |  13148       SimpleIdentifier identifier = EngineTestCase.findNode( | 
 |  13149           unit, code, "e;", (node) => node is SimpleIdentifier); | 
 |  13150       expect(identifier.propagatedType, equals(listOfStringType)); | 
 |  13151     } | 
 |  13152   } | 
 |  13153  | 
|  13115   void test_functionExpression_asInvocationArgument() { |  13154   void test_functionExpression_asInvocationArgument() { | 
|  13116     String code = r''' |  13155     String code = r''' | 
|  13117 class MyMap<K, V> { |  13156 class MyMap<K, V> { | 
|  13118   forEach(f(K key, V value)) {} |  13157   forEach(f(K key, V value)) {} | 
|  13119 } |  13158 } | 
|  13120 f(MyMap<int, String> m) { |  13159 f(MyMap<int, String> m) { | 
|  13121   m.forEach((k, v) { |  13160   m.forEach((k, v) { | 
|  13122     k; |  13161     k; | 
|  13123     v; |  13162     v; | 
|  13124   }); |  13163   }); | 
| (...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  15029  |  15068  | 
|  15030   void _resolveTestUnit(String code) { |  15069   void _resolveTestUnit(String code) { | 
|  15031     testCode = code; |  15070     testCode = code; | 
|  15032     testSource = addSource(testCode); |  15071     testSource = addSource(testCode); | 
|  15033     LibraryElement library = resolve2(testSource); |  15072     LibraryElement library = resolve2(testSource); | 
|  15034     assertNoErrors(testSource); |  15073     assertNoErrors(testSource); | 
|  15035     verify([testSource]); |  15074     verify([testSource]); | 
|  15036     testUnit = resolveCompilationUnit(testSource, library); |  15075     testUnit = resolveCompilationUnit(testSource, library); | 
|  15037   } |  15076   } | 
|  15038 } |  15077 } | 
| OLD | NEW |