| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:analyzer/src/summary/format.dart'; | 5 import 'package:analyzer/src/summary/format.dart'; |
| 6 import 'package:analyzer/src/summary/link.dart'; | 6 import 'package:analyzer/src/summary/link.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import '../../reflective_tests.dart'; | 9 import '../../reflective_tests.dart'; |
| 10 import 'summarize_ast_test.dart'; | 10 import 'summarize_ast_test.dart'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 class C<T> extends B<T> { | 89 class C<T> extends B<T> { |
| 90 Future<T> f() => null; | 90 Future<T> f() => null; |
| 91 } | 91 } |
| 92 '''); | 92 '''); |
| 93 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 93 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 94 library.libraryCycleForLink.ensureLinked(); | 94 library.libraryCycleForLink.ensureLinked(); |
| 95 // No assertions--just make sure it doesn't crash. | 95 // No assertions--just make sure it doesn't crash. |
| 96 } | 96 } |
| 97 | 97 |
| 98 void test_baseClass_genericWithStaticFinal() { |
| 99 createLinker(''' |
| 100 class B<T> { |
| 101 static final int i = 0; |
| 102 } |
| 103 class C<T> extends B<T> { |
| 104 void f() {} |
| 105 } |
| 106 '''); |
| 107 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 108 library.libraryCycleForLink.ensureLinked(); |
| 109 } |
| 110 |
| 98 void test_baseClass_withPrivateField() { | 111 void test_baseClass_withPrivateField() { |
| 99 createLinker(''' | 112 createLinker(''' |
| 100 class B { | 113 class B { |
| 101 var _b; | 114 var _b; |
| 102 } | 115 } |
| 103 class C extends B { | 116 class C extends B { |
| 104 var c; | 117 var c; |
| 105 } | 118 } |
| 106 '''); | 119 '''); |
| 107 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 120 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 class C { | 206 class C { |
| 194 static var y = x; | 207 static var y = x; |
| 195 } | 208 } |
| 196 '''); | 209 '''); |
| 197 expect( | 210 expect( |
| 198 linker | 211 linker |
| 199 .getLibrary(linkerInputs.testDartUri) | 212 .getLibrary(linkerInputs.testDartUri) |
| 200 .getContainedName('C') | 213 .getContainedName('C') |
| 201 .getContainedName('y') | 214 .getContainedName('y') |
| 202 .asTypeInferenceNode | 215 .asTypeInferenceNode |
| 216 .variableElement |
| 203 .inferredType | 217 .inferredType |
| 204 .toString(), | 218 .toString(), |
| 205 'dynamic'); | 219 'dynamic'); |
| 206 } | 220 } |
| 207 | 221 |
| 208 void test_inferredType_topLevelVariable_dynamic() { | 222 void test_inferredType_topLevelVariable_dynamic() { |
| 209 createLinker(''' | 223 createLinker(''' |
| 210 dynamic x = null; | 224 dynamic x = null; |
| 211 var y = x; | 225 var y = x; |
| 212 '''); | 226 '''); |
| 213 expect( | 227 expect( |
| 214 linker | 228 linker |
| 215 .getLibrary(linkerInputs.testDartUri) | 229 .getLibrary(linkerInputs.testDartUri) |
| 216 .getContainedName('y') | 230 .getContainedName('y') |
| 217 .asTypeInferenceNode | 231 .asTypeInferenceNode |
| 232 .variableElement |
| 218 .inferredType | 233 .inferredType |
| 219 .toString(), | 234 .toString(), |
| 220 'dynamic'); | 235 'dynamic'); |
| 221 } | 236 } |
| 222 | 237 |
| 223 void test_inferredTypeFromOutsideBuildUnit_dynamic() { | 238 void test_inferredTypeFromOutsideBuildUnit_dynamic() { |
| 224 var bundle = createPackageBundle( | 239 var bundle = createPackageBundle( |
| 225 ''' | 240 ''' |
| 226 var x; | 241 var x; |
| 227 var y = x; // Inferred type: dynamic | 242 var y = x; // Inferred type: dynamic |
| 228 ''', | 243 ''', |
| 229 path: '/a.dart'); | 244 path: '/a.dart'); |
| 230 addBundle(bundle); | 245 addBundle(bundle); |
| 231 createLinker(''' | 246 createLinker(''' |
| 232 import 'a.dart'; | 247 import 'a.dart'; |
| 233 var z = y; // Inferred type: dynamic | 248 var z = y; // Inferred type: dynamic |
| 234 '''); | 249 '''); |
| 235 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 250 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 236 expect( | 251 expect( |
| 237 library | 252 library |
| 238 .getContainedName('z') | 253 .getContainedName('z') |
| 239 .asTypeInferenceNode | 254 .asTypeInferenceNode |
| 255 .variableElement |
| 240 .inferredType | 256 .inferredType |
| 241 .toString(), | 257 .toString(), |
| 242 'dynamic'); | 258 'dynamic'); |
| 243 } | 259 } |
| 244 | 260 |
| 245 void test_inferredTypeFromOutsideBuildUnit_instanceField() { | 261 void test_inferredTypeFromOutsideBuildUnit_instanceField() { |
| 246 var bundle = createPackageBundle( | 262 var bundle = createPackageBundle( |
| 247 ''' | 263 ''' |
| 248 class C { | 264 class C { |
| 249 var f = 0; // Inferred type: int | 265 var f = 0; // Inferred type: int |
| 250 } | 266 } |
| 251 ''', | 267 ''', |
| 252 path: '/a.dart'); | 268 path: '/a.dart'); |
| 253 addBundle(bundle); | 269 addBundle(bundle); |
| 254 createLinker(''' | 270 createLinker(''' |
| 255 import 'a.dart'; | 271 import 'a.dart'; |
| 256 var x = new C().f; // Inferred type: int | 272 var x = new C().f; // Inferred type: int |
| 257 '''); | 273 '''); |
| 258 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 274 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 259 expect( | 275 expect( |
| 260 library | 276 library |
| 261 .getContainedName('x') | 277 .getContainedName('x') |
| 262 .asTypeInferenceNode | 278 .asTypeInferenceNode |
| 279 .variableElement |
| 263 .inferredType | 280 .inferredType |
| 264 .toString(), | 281 .toString(), |
| 265 'int'); | 282 'int'); |
| 266 } | 283 } |
| 267 | 284 |
| 285 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { |
| 286 var bundle = createPackageBundle( |
| 287 ''' |
| 288 class C { |
| 289 var f = 0; // Inferred type: int |
| 290 } |
| 291 ''', |
| 292 path: '/a.dart'); |
| 293 addBundle(bundle); |
| 294 createLinker(''' |
| 295 import 'a.dart'; |
| 296 class D { |
| 297 var g = new C().f; // Inferred type: int |
| 298 } |
| 299 '''); |
| 300 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 301 ClassElementForLink_Class classD = library.getContainedName('D'); |
| 302 expect(classD.fields[0].inferredType.toString(), 'int'); |
| 303 } |
| 304 |
| 268 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() { | 305 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() { |
| 269 var bundle = createPackageBundle( | 306 var bundle = createPackageBundle( |
| 270 ''' | 307 ''' |
| 271 class B { | 308 class B { |
| 272 T f<T>(T t) => t; | 309 T f<T>(T t) => t; |
| 273 } | 310 } |
| 274 class C extends B { | 311 class C extends B { |
| 275 f<T>(t) => t; // Inferred param type: T | 312 f<T>(t) => t; // Inferred param type: T |
| 276 } | 313 } |
| 277 ''', | 314 ''', |
| 278 path: '/a.dart'); | 315 path: '/a.dart'); |
| 279 addBundle(bundle); | 316 addBundle(bundle); |
| 280 createLinker(''' | 317 createLinker(''' |
| 281 import 'a.dart'; | 318 import 'a.dart'; |
| 282 var x = new C().f(0); // Inferred type: int | 319 var x = new C().f(0); // Inferred type: int |
| 283 '''); | 320 '''); |
| 284 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 321 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 285 expect( | 322 expect( |
| 286 library | 323 library |
| 287 .getContainedName('x') | 324 .getContainedName('x') |
| 288 .asTypeInferenceNode | 325 .asTypeInferenceNode |
| 326 .variableElement |
| 289 .inferredType | 327 .inferredType |
| 290 .toString(), | 328 .toString(), |
| 291 'int'); | 329 'int'); |
| 292 } | 330 } |
| 293 | 331 |
| 294 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { | 332 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { |
| 295 var bundle = createPackageBundle( | 333 var bundle = createPackageBundle( |
| 296 ''' | 334 ''' |
| 297 class B { | 335 class B { |
| 298 void f(int i) {} | 336 void f(int i) {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 addBundle(bundle); | 370 addBundle(bundle); |
| 333 createLinker(''' | 371 createLinker(''' |
| 334 import 'a.dart'; | 372 import 'a.dart'; |
| 335 var x = new C().f(); // Inferred type: int | 373 var x = new C().f(); // Inferred type: int |
| 336 '''); | 374 '''); |
| 337 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 375 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 338 expect( | 376 expect( |
| 339 library | 377 library |
| 340 .getContainedName('x') | 378 .getContainedName('x') |
| 341 .asTypeInferenceNode | 379 .asTypeInferenceNode |
| 380 .variableElement |
| 342 .inferredType | 381 .inferredType |
| 343 .toString(), | 382 .toString(), |
| 344 'int'); | 383 'int'); |
| 345 } | 384 } |
| 346 | 385 |
| 347 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaInheritance() { | 386 void test_inferredTypeFromOutsideBuildUnit_methodReturnType_viaInheritance() { |
| 348 var bundle = createPackageBundle( | 387 var bundle = createPackageBundle( |
| 349 ''' | 388 ''' |
| 350 class B { | 389 class B { |
| 351 int f() => 0; | 390 int f() => 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 372 void test_inferredTypeFromOutsideBuildUnit_staticField() { | 411 void test_inferredTypeFromOutsideBuildUnit_staticField() { |
| 373 var bundle = | 412 var bundle = |
| 374 createPackageBundle('class C { static var f = 0; }', path: '/a.dart'); | 413 createPackageBundle('class C { static var f = 0; }', path: '/a.dart'); |
| 375 addBundle(bundle); | 414 addBundle(bundle); |
| 376 createLinker('import "a.dart"; var x = C.f;', path: '/b.dart'); | 415 createLinker('import "a.dart"; var x = C.f;', path: '/b.dart'); |
| 377 expect( | 416 expect( |
| 378 linker | 417 linker |
| 379 .getLibrary(linkerInputs.testDartUri) | 418 .getLibrary(linkerInputs.testDartUri) |
| 380 .getContainedName('x') | 419 .getContainedName('x') |
| 381 .asTypeInferenceNode | 420 .asTypeInferenceNode |
| 421 .variableElement |
| 382 .inferredType | 422 .inferredType |
| 383 .toString(), | 423 .toString(), |
| 384 'int'); | 424 'int'); |
| 385 } | 425 } |
| 386 | 426 |
| 387 void test_inferredTypeFromOutsideBuildUnit_topLevelVariable() { | 427 void test_inferredTypeFromOutsideBuildUnit_topLevelVariable() { |
| 388 var bundle = createPackageBundle('var a = 0;', path: '/a.dart'); | 428 var bundle = createPackageBundle('var a = 0;', path: '/a.dart'); |
| 389 addBundle(bundle); | 429 addBundle(bundle); |
| 390 createLinker('import "a.dart"; var b = a;', path: '/b.dart'); | 430 createLinker('import "a.dart"; var b = a;', path: '/b.dart'); |
| 391 expect( | 431 expect( |
| 392 linker | 432 linker |
| 393 .getLibrary(linkerInputs.testDartUri) | 433 .getLibrary(linkerInputs.testDartUri) |
| 394 .getContainedName('b') | 434 .getContainedName('b') |
| 395 .asTypeInferenceNode | 435 .asTypeInferenceNode |
| 436 .variableElement |
| 396 .inferredType | 437 .inferredType |
| 397 .toString(), | 438 .toString(), |
| 398 'int'); | 439 'int'); |
| 399 } | 440 } |
| 400 | 441 |
| 401 void test_libraryCycle_ignoresDependenciesOutsideBuildUnit() { | 442 void test_libraryCycle_ignoresDependenciesOutsideBuildUnit() { |
| 402 createLinker('import "dart:async";'); | 443 createLinker('import "dart:async";'); |
| 403 LibraryCycleForLink libraryCycle = testLibrary.libraryCycleForLink; | 444 LibraryCycleForLink libraryCycle = testLibrary.libraryCycleForLink; |
| 404 expect(libraryCycle.dependencies, isEmpty); | 445 expect(libraryCycle.dependencies, isEmpty); |
| 405 expect(libraryCycle.libraries, [testLibrary]); | 446 expect(libraryCycle.libraries, [testLibrary]); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 class C extends B with I {} | 534 class C extends B with I {} |
| 494 class D extends C { | 535 class D extends C { |
| 495 void f() {} | 536 void f() {} |
| 496 } | 537 } |
| 497 '''); | 538 '''); |
| 498 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 539 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 499 library.libraryCycleForLink.ensureLinked(); | 540 library.libraryCycleForLink.ensureLinked(); |
| 500 // No assertions--just make sure it doesn't crash. | 541 // No assertions--just make sure it doesn't crash. |
| 501 } | 542 } |
| 502 } | 543 } |
| OLD | NEW |