| 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 12155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12166 _resolveTestUnit(code); | 12166 _resolveTestUnit(code); |
| 12167 | 12167 |
| 12168 SimpleIdentifier identifier = _findIdentifier('foo'); | 12168 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 12169 VariableDeclaration declaration = | 12169 VariableDeclaration declaration = |
| 12170 identifier.getAncestor((node) => node is VariableDeclaration); | 12170 identifier.getAncestor((node) => node is VariableDeclaration); |
| 12171 expect(declaration.initializer.staticType.name, 'String'); | 12171 expect(declaration.initializer.staticType.name, 'String'); |
| 12172 expect(declaration.initializer.propagatedType, isNull); | 12172 expect(declaration.initializer.propagatedType, isNull); |
| 12173 } | 12173 } |
| 12174 | 12174 |
| 12175 void test_genericFunction() { | 12175 void test_genericFunction() { |
| 12176 if (!AnalysisEngine.instance.useTaskModel) { |
| 12177 return; |
| 12178 } |
| 12176 // TODO(jmesserly): we're missing a case in the parser for the return type, | 12179 // TODO(jmesserly): we're missing a case in the parser for the return type, |
| 12177 // so "dynamic" must be used to workaround this. | 12180 // so "dynamic" must be used to workaround this. |
| 12178 _resolveTestUnit(r''' | 12181 _resolveTestUnit(r''' |
| 12179 dynamic/*=T*/ f/*<T>*/(/*=T*/ x) => null; | 12182 dynamic/*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 12180 '''); | 12183 '''); |
| 12181 SimpleIdentifier f = _findIdentifier('f'); | 12184 SimpleIdentifier f = _findIdentifier('f'); |
| 12182 FunctionElementImpl e = f.staticElement; | 12185 FunctionElementImpl e = f.staticElement; |
| 12183 expect(e.typeParameters.toString(), '[T]'); | 12186 expect(e.typeParameters.toString(), '[T]'); |
| 12184 expect(e.type.typeParameters.toString(), '[T]'); | 12187 expect(e.type.typeParameters.toString(), '[T]'); |
| 12185 expect(e.type.typeParameters[0].type, e.type.typeArguments[0]); | 12188 expect(e.type.typeParameters[0].type, e.type.typeArguments[0]); |
| 12186 expect(e.type.toString(), '(T) → T'); | 12189 expect(e.type.toString(), '(T) → T'); |
| 12187 | 12190 |
| 12188 // Substitute for T | 12191 // Substitute for T |
| 12189 DartType t = e.typeParameters[0].type; | 12192 DartType t = e.typeParameters[0].type; |
| 12190 FunctionType ft = e.type.substitute2([typeProvider.stringType], [t]); | 12193 FunctionType ft = e.type.substitute2([typeProvider.stringType], [t]); |
| 12191 expect(ft.toString(), '(String) → String'); | 12194 expect(ft.toString(), '(String) → String'); |
| 12192 } | 12195 } |
| 12193 | 12196 |
| 12194 void test_genericMethod() { | 12197 void test_genericMethod() { |
| 12198 if (!AnalysisEngine.instance.useTaskModel) { |
| 12199 return; |
| 12200 } |
| 12195 _resolveTestUnit(r''' | 12201 _resolveTestUnit(r''' |
| 12196 class C<E> { | 12202 class C<E> { |
| 12197 List/*<T>*/ f/*<T>*/(E e) => null; | 12203 List/*<T>*/ f/*<T>*/(E e) => null; |
| 12198 } | 12204 } |
| 12199 main() { | 12205 main() { |
| 12200 C<String> cOfString; | 12206 C<String> cOfString; |
| 12201 } | 12207 } |
| 12202 '''); | 12208 '''); |
| 12203 SimpleIdentifier f = _findIdentifier('f'); | 12209 SimpleIdentifier f = _findIdentifier('f'); |
| 12204 MethodElementImpl e = f.staticElement; | 12210 MethodElementImpl e = f.staticElement; |
| (...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15163 | 15169 |
| 15164 void _resolveTestUnit(String code) { | 15170 void _resolveTestUnit(String code) { |
| 15165 testCode = code; | 15171 testCode = code; |
| 15166 testSource = addSource(testCode); | 15172 testSource = addSource(testCode); |
| 15167 LibraryElement library = resolve2(testSource); | 15173 LibraryElement library = resolve2(testSource); |
| 15168 assertNoErrors(testSource); | 15174 assertNoErrors(testSource); |
| 15169 verify([testSource]); | 15175 verify([testSource]); |
| 15170 testUnit = resolveCompilationUnit(testSource, library); | 15176 testUnit = resolveCompilationUnit(testSource, library); |
| 15171 } | 15177 } |
| 15172 } | 15178 } |
| OLD | NEW |