| 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 13134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13145 '''; | 13145 '''; |
| 13146 _resolveTestUnit(code); | 13146 _resolveTestUnit(code); |
| 13147 | 13147 |
| 13148 SimpleIdentifier identifier = _findIdentifier('foo'); | 13148 SimpleIdentifier identifier = _findIdentifier('foo'); |
| 13149 VariableDeclaration declaration = | 13149 VariableDeclaration declaration = |
| 13150 identifier.getAncestor((node) => node is VariableDeclaration); | 13150 identifier.getAncestor((node) => node is VariableDeclaration); |
| 13151 expect(declaration.initializer.staticType.name, 'String'); | 13151 expect(declaration.initializer.staticType.name, 'String'); |
| 13152 expect(declaration.initializer.propagatedType, isNull); | 13152 expect(declaration.initializer.propagatedType, isNull); |
| 13153 } | 13153 } |
| 13154 | 13154 |
| 13155 void test_genericFunction_typedef() { |
| 13156 String code = r''' |
| 13157 typedef T F<T>(T x); |
| 13158 F f0; |
| 13159 |
| 13160 class C { |
| 13161 static F f1; |
| 13162 F f2; |
| 13163 void g(F f3) { |
| 13164 F f4; |
| 13165 f0(3); |
| 13166 f1(3); |
| 13167 f2(3); |
| 13168 f3(3); |
| 13169 f4(3); |
| 13170 } |
| 13171 } |
| 13172 |
| 13173 class D<S> { |
| 13174 static F f1; |
| 13175 F f2; |
| 13176 void g(F f3) { |
| 13177 F f4; |
| 13178 f0(3); |
| 13179 f1(3); |
| 13180 f2(3); |
| 13181 f3(3); |
| 13182 f4(3); |
| 13183 } |
| 13184 } |
| 13185 '''; |
| 13186 _resolveTestUnit(code); |
| 13187 |
| 13188 { |
| 13189 List<Statement> statements = |
| 13190 AstFinder.getStatementsInMethod(testUnit, "C", "g"); |
| 13191 |
| 13192 ExpressionStatement exps0 = statements[1]; |
| 13193 ExpressionStatement exps1 = statements[2]; |
| 13194 ExpressionStatement exps2 = statements[3]; |
| 13195 ExpressionStatement exps3 = statements[4]; |
| 13196 ExpressionStatement exps4 = statements[5]; |
| 13197 Expression exp0 = exps0.expression; |
| 13198 Expression exp1 = exps1.expression; |
| 13199 Expression exp2 = exps2.expression; |
| 13200 Expression exp3 = exps3.expression; |
| 13201 Expression exp4 = exps4.expression; |
| 13202 expect(exp0.staticType, typeProvider.dynamicType); |
| 13203 expect(exp1.staticType, typeProvider.dynamicType); |
| 13204 expect(exp2.staticType, typeProvider.dynamicType); |
| 13205 expect(exp3.staticType, typeProvider.dynamicType); |
| 13206 expect(exp4.staticType, typeProvider.dynamicType); |
| 13207 } |
| 13208 { |
| 13209 List<Statement> statements = |
| 13210 AstFinder.getStatementsInMethod(testUnit, "D", "g"); |
| 13211 |
| 13212 ExpressionStatement exps0 = statements[1]; |
| 13213 ExpressionStatement exps1 = statements[2]; |
| 13214 ExpressionStatement exps2 = statements[3]; |
| 13215 ExpressionStatement exps3 = statements[4]; |
| 13216 ExpressionStatement exps4 = statements[5]; |
| 13217 Expression exp0 = exps0.expression; |
| 13218 Expression exp1 = exps1.expression; |
| 13219 Expression exp2 = exps2.expression; |
| 13220 Expression exp3 = exps3.expression; |
| 13221 Expression exp4 = exps4.expression; |
| 13222 expect(exp0.staticType, typeProvider.dynamicType); |
| 13223 expect(exp1.staticType, typeProvider.dynamicType); |
| 13224 expect(exp2.staticType, typeProvider.dynamicType); |
| 13225 expect(exp3.staticType, typeProvider.dynamicType); |
| 13226 expect(exp4.staticType, typeProvider.dynamicType); |
| 13227 } |
| 13228 } |
| 13229 |
| 13155 void test_genericFunction() { | 13230 void test_genericFunction() { |
| 13156 if (!AnalysisEngine.instance.useTaskModel) { | 13231 if (!AnalysisEngine.instance.useTaskModel) { |
| 13157 return; | 13232 return; |
| 13158 } | 13233 } |
| 13159 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); | 13234 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); |
| 13160 SimpleIdentifier f = _findIdentifier('f'); | 13235 SimpleIdentifier f = _findIdentifier('f'); |
| 13161 FunctionElementImpl e = f.staticElement; | 13236 FunctionElementImpl e = f.staticElement; |
| 13162 expect(e.typeParameters.toString(), '[T]'); | 13237 expect(e.typeParameters.toString(), '[T]'); |
| 13163 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13238 expect(e.type.boundTypeParameters.toString(), '[T]'); |
| 13164 expect(e.type.typeParameters.toString(), '[]'); | 13239 expect(e.type.typeParameters.toString(), '[]'); |
| (...skipping 3154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16319 | 16394 |
| 16320 void _resolveTestUnit(String code) { | 16395 void _resolveTestUnit(String code) { |
| 16321 testCode = code; | 16396 testCode = code; |
| 16322 testSource = addSource(testCode); | 16397 testSource = addSource(testCode); |
| 16323 LibraryElement library = resolve2(testSource); | 16398 LibraryElement library = resolve2(testSource); |
| 16324 assertNoErrors(testSource); | 16399 assertNoErrors(testSource); |
| 16325 verify([testSource]); | 16400 verify([testSource]); |
| 16326 testUnit = resolveCompilationUnit(testSource, library); | 16401 testUnit = resolveCompilationUnit(testSource, library); |
| 16327 } | 16402 } |
| 16328 } | 16403 } |
| OLD | NEW |