| 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/dart/element/type.dart'; | 5 import 'package:analyzer/dart/element/type.dart'; |
| 6 import 'package:analyzer/src/dart/element/element.dart'; | 6 import 'package:analyzer/src/dart/element/element.dart'; |
| 7 import 'package:analyzer/src/summary/format.dart'; | 7 import 'package:analyzer/src/summary/format.dart'; |
| 8 import 'package:analyzer/src/summary/idl.dart'; | 8 import 'package:analyzer/src/summary/idl.dart'; |
| 9 import 'package:analyzer/src/summary/link.dart'; | 9 import 'package:analyzer/src/summary/link.dart'; |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 class E {} | 341 class E {} |
| 342 ''', | 342 ''', |
| 343 path: '/a.dart'); | 343 path: '/a.dart'); |
| 344 addBundle('/a.ds', bundle); | 344 addBundle('/a.ds', bundle); |
| 345 createLinker(''' | 345 createLinker(''' |
| 346 import 'a.dart'; | 346 import 'a.dart'; |
| 347 var y = C.x; | 347 var y = C.x; |
| 348 '''); | 348 '''); |
| 349 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 349 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 350 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), | 350 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), |
| 351 '(D) → E'); | 351 '(D) → dynamic'); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void test_inferredType_instanceField_conditional_genericFunctions() { | 354 void test_inferredType_instanceField_conditional_genericFunctions() { |
| 355 createLinker(''' | 355 createLinker(''' |
| 356 class C { | 356 class C { |
| 357 final f = true ? <T>(T t) => 0 : <T>(T t) => 1; | 357 final f = true ? <T>(T t) => 0 : <T>(T t) => 1; |
| 358 } | 358 } |
| 359 '''); | 359 '''); |
| 360 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 360 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 361 library.libraryCycleForLink.ensureLinked(); | 361 library.libraryCycleForLink.ensureLinked(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 var bundle = createPackageBundle( | 482 var bundle = createPackageBundle( |
| 483 ''' | 483 ''' |
| 484 class C { | 484 class C { |
| 485 var f = 0; // Inferred type: int | 485 var f = 0; // Inferred type: int |
| 486 } | 486 } |
| 487 ''', | 487 ''', |
| 488 path: '/a.dart'); | 488 path: '/a.dart'); |
| 489 addBundle('/a.ds', bundle); | 489 addBundle('/a.ds', bundle); |
| 490 createLinker(''' | 490 createLinker(''' |
| 491 import 'a.dart'; | 491 import 'a.dart'; |
| 492 var x = new C().f; // Inferred type: int | 492 var x = new C().f; // Inferred type: dynamic |
| 493 '''); | 493 '''); |
| 494 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 494 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 495 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), | 495 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), |
| 496 'int'); | 496 'dynamic'); |
| 497 } | 497 } |
| 498 | 498 |
| 499 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { | 499 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { |
| 500 var bundle = createPackageBundle( | 500 var bundle = createPackageBundle( |
| 501 ''' | 501 ''' |
| 502 class C { | 502 class C { |
| 503 var f = 0; // Inferred type: int | 503 var f = 0; // Inferred type: int |
| 504 } | 504 } |
| 505 ''', | 505 ''', |
| 506 path: '/a.dart'); | 506 path: '/a.dart'); |
| 507 addBundle('/a.ds', bundle); | 507 addBundle('/a.ds', bundle); |
| 508 createLinker(''' | 508 createLinker(''' |
| 509 import 'a.dart'; | 509 import 'a.dart'; |
| 510 class D { | 510 class D { |
| 511 var g = new C().f; // Inferred type: int | 511 var g = new C().f; // Inferred type: dynamic |
| 512 } | 512 } |
| 513 '''); | 513 '''); |
| 514 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 514 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 515 ClassElementForLink_Class classD = library.getContainedName('D'); | 515 ClassElementForLink_Class classD = library.getContainedName('D'); |
| 516 expect(classD.fields[0].inferredType.toString(), 'int'); | 516 expect(classD.fields[0].inferredType.toString(), 'dynamic'); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() { | 519 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() { |
| 520 var bundle = createPackageBundle( | 520 var bundle = createPackageBundle( |
| 521 ''' | 521 ''' |
| 522 class B { | 522 class B { |
| 523 T f<T>(T t) => t; | 523 T f<T>(T t) => t; |
| 524 } | 524 } |
| 525 class C extends B { | 525 class C extends B { |
| 526 f<T>(t) => t; // Inferred param type: T | 526 f<T>(t) => t; // Inferred param type: T |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 */ | 965 */ |
| 966 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { | 966 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { |
| 967 for (EntityRef ref in unit.types) { | 967 for (EntityRef ref in unit.types) { |
| 968 if (ref.slot == slot) { | 968 if (ref.slot == slot) { |
| 969 return ref; | 969 return ref; |
| 970 } | 970 } |
| 971 } | 971 } |
| 972 return null; | 972 return null; |
| 973 } | 973 } |
| 974 } | 974 } |
| OLD | NEW |