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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 331 } |
332 class E {} | 332 class E {} |
333 ''', path: '/a.dart'); | 333 ''', path: '/a.dart'); |
334 addBundle('/a.ds', bundle); | 334 addBundle('/a.ds', bundle); |
335 createLinker(''' | 335 createLinker(''' |
336 import 'a.dart'; | 336 import 'a.dart'; |
337 var y = C.x; | 337 var y = C.x; |
338 '''); | 338 '''); |
339 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 339 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
340 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), | 340 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), |
341 '(D) → dynamic'); | 341 '(D) → E'); |
342 } | 342 } |
343 | 343 |
344 void test_inferredType_implicitFunctionTypeIndices() { | 344 void test_inferredType_implicitFunctionTypeIndices() { |
345 var bundle = createPackageBundle(''' | 345 var bundle = createPackageBundle(''' |
346 class A { | 346 class A { |
347 void foo(void bar(int arg)) {} | 347 void foo(void bar(int arg)) {} |
348 } | 348 } |
349 class B extends A { | 349 class B extends A { |
350 void foo(bar) {} | 350 void foo(bar) {} |
351 } | 351 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 518 |
519 void test_inferredTypeFromOutsideBuildUnit_instanceField() { | 519 void test_inferredTypeFromOutsideBuildUnit_instanceField() { |
520 var bundle = createPackageBundle(''' | 520 var bundle = createPackageBundle(''' |
521 class C { | 521 class C { |
522 var f = 0; // Inferred type: int | 522 var f = 0; // Inferred type: int |
523 } | 523 } |
524 ''', path: '/a.dart'); | 524 ''', path: '/a.dart'); |
525 addBundle('/a.ds', bundle); | 525 addBundle('/a.ds', bundle); |
526 createLinker(''' | 526 createLinker(''' |
527 import 'a.dart'; | 527 import 'a.dart'; |
528 var x = new C().f; // Inferred type: dynamic | 528 var x = new C().f; // Inferred type: int |
529 '''); | 529 '''); |
530 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 530 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
531 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), | 531 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), |
532 'dynamic'); | 532 'int'); |
533 } | 533 } |
534 | 534 |
535 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { | 535 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { |
536 var bundle = createPackageBundle(''' | 536 var bundle = createPackageBundle(''' |
537 class C { | 537 class C { |
538 var f = 0; // Inferred type: int | 538 var f = 0; // Inferred type: int |
539 } | 539 } |
540 ''', path: '/a.dart'); | 540 ''', path: '/a.dart'); |
541 addBundle('/a.ds', bundle); | 541 addBundle('/a.ds', bundle); |
542 createLinker(''' | 542 createLinker(''' |
543 import 'a.dart'; | 543 import 'a.dart'; |
544 class D { | 544 class D { |
545 var g = new C().f; // Inferred type: dynamic | 545 var g = new C().f; // Inferred type: int |
546 } | 546 } |
547 '''); | 547 '''); |
548 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 548 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
549 ClassElementForLink_Class classD = library.getContainedName('D'); | 549 ClassElementForLink_Class classD = library.getContainedName('D'); |
550 expect(classD.fields[0].inferredType.toString(), 'dynamic'); | 550 expect(classD.fields[0].inferredType.toString(), 'int'); |
551 } | 551 } |
552 | 552 |
553 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { | 553 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { |
554 var bundle = createPackageBundle(''' | 554 var bundle = createPackageBundle(''' |
555 class B { | 555 class B { |
556 void f(int i) {} | 556 void f(int i) {} |
557 } | 557 } |
558 class C extends B { | 558 class C extends B { |
559 f(i) {} // Inferred param type: int | 559 f(i) {} // Inferred param type: int |
560 } | 560 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 */ | 963 */ |
964 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { | 964 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { |
965 for (EntityRef ref in unit.types) { | 965 for (EntityRef ref in unit.types) { |
966 if (ref.slot == slot) { | 966 if (ref.slot == slot) { |
967 return ref; | 967 return ref; |
968 } | 968 } |
969 } | 969 } |
970 return null; | 970 return null; |
971 } | 971 } |
972 } | 972 } |
OLD | NEW |