| 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 20 matching lines...) Expand all Loading... |
| 31 Map<String, LinkedLibraryBuilder> linkedLibraries = | 31 Map<String, LinkedLibraryBuilder> linkedLibraries = |
| 32 setupForLink(linkerInputs.linkedLibraries, linkerInputs.getUnit); | 32 setupForLink(linkerInputs.linkedLibraries, linkerInputs.getUnit); |
| 33 linker = new Linker(linkedLibraries, linkerInputs.getDependency, | 33 linker = new Linker(linkedLibraries, linkerInputs.getDependency, |
| 34 linkerInputs.getUnit, true); | 34 linkerInputs.getUnit, true); |
| 35 } | 35 } |
| 36 | 36 |
| 37 LibraryElementForLink getLibrary(String uri) { | 37 LibraryElementForLink getLibrary(String uri) { |
| 38 return linker.getLibrary(Uri.parse(uri)); | 38 return linker.getLibrary(Uri.parse(uri)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void test_baseClass_withPrivateField() { |
| 42 createLinker(''' |
| 43 class B { |
| 44 var _b; |
| 45 } |
| 46 class C extends B { |
| 47 var c; |
| 48 } |
| 49 '''); |
| 50 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 51 library.libraryCycleForLink.ensureLinked(); |
| 52 // No assertions--just make sure it doesn't crash. |
| 53 } |
| 54 |
| 41 void test_inferredType_instanceField_dynamic() { | 55 void test_inferredType_instanceField_dynamic() { |
| 42 createLinker(''' | 56 createLinker(''' |
| 43 var x; | 57 var x; |
| 44 class C { | 58 class C { |
| 45 var f = x; // Inferred type: dynamic | 59 var f = x; // Inferred type: dynamic |
| 46 } | 60 } |
| 47 '''); | 61 '''); |
| 48 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 62 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 49 library.libraryCycleForLink.ensureLinked(); | 63 library.libraryCycleForLink.ensureLinked(); |
| 50 ClassElementForLink_Class cls = library.getContainedName('C'); | 64 ClassElementForLink_Class cls = library.getContainedName('C'); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 f() {} // Inferred return type: dynamic | 94 f() {} // Inferred return type: dynamic |
| 81 } | 95 } |
| 82 '''); | 96 '''); |
| 83 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 97 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 84 library.libraryCycleForLink.ensureLinked(); | 98 library.libraryCycleForLink.ensureLinked(); |
| 85 ClassElementForLink_Class cls = library.getContainedName('C'); | 99 ClassElementForLink_Class cls = library.getContainedName('C'); |
| 86 expect(cls.methods, hasLength(1)); | 100 expect(cls.methods, hasLength(1)); |
| 87 expect(cls.methods[0].returnType.toString(), 'dynamic'); | 101 expect(cls.methods[0].returnType.toString(), 'dynamic'); |
| 88 } | 102 } |
| 89 | 103 |
| 104 void test_inferredType_methodReturnType_void() { |
| 105 createLinker(''' |
| 106 class B { |
| 107 void f() {} |
| 108 } |
| 109 class C extends B { |
| 110 f() {} |
| 111 } |
| 112 '''); |
| 113 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 114 library.libraryCycleForLink.ensureLinked(); |
| 115 ClassElementForLink_Class cls = library.getContainedName('C'); |
| 116 expect(cls.methods, hasLength(1)); |
| 117 expect(cls.methods[0].returnType.toString(), 'void'); |
| 118 } |
| 119 |
| 90 void test_inferredType_staticField_dynamic() { | 120 void test_inferredType_staticField_dynamic() { |
| 91 createLinker(''' | 121 createLinker(''' |
| 92 dynamic x = null; | 122 dynamic x = null; |
| 93 class C { | 123 class C { |
| 94 static var y = x; | 124 static var y = x; |
| 95 } | 125 } |
| 96 '''); | 126 '''); |
| 97 expect( | 127 expect( |
| 98 linker | 128 linker |
| 99 .getLibrary(linkerInputs.testDartUri) | 129 .getLibrary(linkerInputs.testDartUri) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | 214 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); |
| 185 expect( | 215 expect( |
| 186 library | 216 library |
| 187 .getContainedName('x') | 217 .getContainedName('x') |
| 188 .asTypeInferenceNode | 218 .asTypeInferenceNode |
| 189 .inferredType | 219 .inferredType |
| 190 .toString(), | 220 .toString(), |
| 191 'int'); | 221 'int'); |
| 192 } | 222 } |
| 193 | 223 |
| 194 void test_inferredType_methodReturnType_void() { | |
| 195 createLinker(''' | |
| 196 class B { | |
| 197 void f() {} | |
| 198 } | |
| 199 class C extends B { | |
| 200 f() {} | |
| 201 } | |
| 202 '''); | |
| 203 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); | |
| 204 library.libraryCycleForLink.ensureLinked(); | |
| 205 ClassElementForLink_Class cls = library.getContainedName('C'); | |
| 206 expect(cls.methods, hasLength(1)); | |
| 207 expect(cls.methods[0].returnType.toString(), 'void'); | |
| 208 } | |
| 209 | |
| 210 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { | 224 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaInheritance() { |
| 211 var bundle = createPackageBundle( | 225 var bundle = createPackageBundle( |
| 212 ''' | 226 ''' |
| 213 class B { | 227 class B { |
| 214 void f(int i) {} | 228 void f(int i) {} |
| 215 } | 229 } |
| 216 class C extends B { | 230 class C extends B { |
| 217 f(i) {} // Inferred param type: int | 231 f(i) {} // Inferred param type: int |
| 218 } | 232 } |
| 219 ''', | 233 ''', |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 addNamedSource('/b.dart', ''); | 405 addNamedSource('/b.dart', ''); |
| 392 createLinker('import "a.dart"; import "b.dart";'); | 406 createLinker('import "a.dart"; import "b.dart";'); |
| 393 LibraryElementForLink libA = getLibrary('file:///a.dart'); | 407 LibraryElementForLink libA = getLibrary('file:///a.dart'); |
| 394 LibraryElementForLink libB = getLibrary('file:///b.dart'); | 408 LibraryElementForLink libB = getLibrary('file:///b.dart'); |
| 395 LibraryCycleForLink libraryCycle = testLibrary.libraryCycleForLink; | 409 LibraryCycleForLink libraryCycle = testLibrary.libraryCycleForLink; |
| 396 expect(libraryCycle.dependencies, | 410 expect(libraryCycle.dependencies, |
| 397 unorderedEquals([libA.libraryCycleForLink, libB.libraryCycleForLink])); | 411 unorderedEquals([libA.libraryCycleForLink, libB.libraryCycleForLink])); |
| 398 expect(libraryCycle.libraries, [testLibrary]); | 412 expect(libraryCycle.libraries, [testLibrary]); |
| 399 } | 413 } |
| 400 } | 414 } |
| OLD | NEW |