Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } | 307 } |
| 308 return i; | 308 return i; |
| 309 } | 309 } |
| 310 found.add(dep.uri); | 310 found.add(dep.uri); |
| 311 } | 311 } |
| 312 fail('Did not find dependency $relativeUri. Found: $found'); | 312 fail('Did not find dependency $relativeUri. Found: $found'); |
| 313 return null; | 313 return null; |
| 314 } | 314 } |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * Test an inferred type. If strong mode is disabled, verify that the given | 317 * Test an inferred type. If [onlyInStrongMode] is `true` (the default) and |
| 318 * [slotId] exists and has no associated type. Otherwise, behave as in | 318 * strong mode is disabled, verify that the given [slotId] exists and has no |
| 319 * [checkLinkedTypeSlot]. | 319 * associated type. Otherwise, behave as in [checkLinkedTypeSlot]. |
| 320 */ | 320 */ |
| 321 void checkInferredTypeSlot( | 321 void checkInferredTypeSlot( |
| 322 int slotId, String absoluteUri, String relativeUri, String expectedName, | 322 int slotId, String absoluteUri, String relativeUri, String expectedName, |
| 323 {bool allowTypeParameters: false, | 323 {bool allowTypeParameters: false, |
| 324 ReferenceKind expectedKind: ReferenceKind.classOrEnum, | 324 ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| 325 int expectedTargetUnit: 0, | 325 int expectedTargetUnit: 0, |
| 326 LinkedUnit linkedSourceUnit, | 326 LinkedUnit linkedSourceUnit, |
| 327 UnlinkedUnit unlinkedSourceUnit, | 327 UnlinkedUnit unlinkedSourceUnit, |
| 328 int numTypeParameters: 0}) { | 328 int numTypeParameters: 0, |
| 329 if (strongMode) { | 329 bool onlyInStrongMode: true}) { |
| 330 if (strongMode || !onlyInStrongMode) { | |
| 330 checkLinkedTypeSlot(slotId, absoluteUri, relativeUri, expectedName, | 331 checkLinkedTypeSlot(slotId, absoluteUri, relativeUri, expectedName, |
| 331 allowTypeArguments: allowTypeParameters, | 332 allowTypeArguments: allowTypeParameters, |
| 332 expectedKind: expectedKind, | 333 expectedKind: expectedKind, |
| 333 expectedTargetUnit: expectedTargetUnit, | 334 expectedTargetUnit: expectedTargetUnit, |
| 334 linkedSourceUnit: linkedSourceUnit, | 335 linkedSourceUnit: linkedSourceUnit, |
| 335 unlinkedSourceUnit: unlinkedSourceUnit, | 336 unlinkedSourceUnit: unlinkedSourceUnit, |
| 336 numTypeParameters: numTypeParameters); | 337 numTypeParameters: numTypeParameters); |
| 337 } else { | 338 } else { |
| 338 // A slot id should have been assigned but it should not be associated | 339 // A slot id should have been assigned but it should not be associated |
| 339 // with any type. | 340 // with any type. |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 test_class_type_param_no_bound() { | 1311 test_class_type_param_no_bound() { |
| 1311 String text = 'class C<T> {}'; | 1312 String text = 'class C<T> {}'; |
| 1312 UnlinkedClass cls = serializeClassText(text); | 1313 UnlinkedClass cls = serializeClassText(text); |
| 1313 expect(cls.typeParameters, hasLength(1)); | 1314 expect(cls.typeParameters, hasLength(1)); |
| 1314 expect(cls.typeParameters[0].name, 'T'); | 1315 expect(cls.typeParameters[0].name, 'T'); |
| 1315 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); | 1316 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); |
| 1316 expect(cls.typeParameters[0].bound, isNull); | 1317 expect(cls.typeParameters[0].bound, isNull); |
| 1317 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); | 1318 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); |
| 1318 } | 1319 } |
| 1319 | 1320 |
| 1321 test_closure_executable_with_bottom_return_type() { | |
| 1322 UnlinkedExecutable executable = | |
| 1323 serializeExecutableText('f() { print((() => null)()); }'); | |
| 1324 expect(executable.localFunctions, hasLength(1)); | |
| 1325 expect(executable.localFunctions[0].returnType, isNull); | |
| 1326 if (strongMode) { | |
| 1327 // Strong mode infers a type for the closure of `() => dynamic`, so the | |
| 1328 // inferred return type slot should be empty. | |
| 1329 expect( | |
| 1330 getTypeRefForSlot( | |
| 1331 executable.localFunctions[0].inferredReturnTypeSlot), | |
| 1332 isNull); | |
| 1333 } else { | |
| 1334 // Strong mode infers a type for the closure of `() => dynamic`, so the | |
| 1335 // inferred return type slot should be empty. | |
|
scheglov
2016/02/18 18:11:44
Remove these two lines?
Paul Berry
2016/02/18 18:18:15
Done.
| |
| 1336 // Spec mode infers a type for the closure of `() => Bottom`. | |
| 1337 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, | |
| 1338 null, null, '*bottom*', | |
| 1339 onlyInStrongMode: false); | |
| 1340 } | |
| 1341 } | |
| 1342 | |
| 1343 test_closure_executable_with_imported_return_type() { | |
| 1344 addNamedSource('/a.dart', 'class C { D d; } class D {}'); | |
| 1345 // The closure has type `() => D`; `D` is defined in a library that is | |
| 1346 // imported. | |
| 1347 UnlinkedExecutable executable = serializeExecutableText( | |
| 1348 'import "a.dart"; f() { print((() => new C().d)()); }'); | |
| 1349 expect(executable.localFunctions, hasLength(1)); | |
| 1350 expect(executable.localFunctions[0].returnType, isNull); | |
| 1351 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, | |
| 1352 absUri('/a.dart'), 'a.dart', 'D', | |
| 1353 onlyInStrongMode: false); | |
| 1354 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); | |
| 1355 } | |
| 1356 | |
| 1357 test_closure_executable_with_unimported_return_type() { | |
| 1358 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); | |
| 1359 addNamedSource('/b.dart', 'class D {}'); | |
| 1360 // The closure has type `() => D`; `D` is defined in a library that is not | |
| 1361 // imported. | |
| 1362 UnlinkedExecutable executable = serializeExecutableText( | |
| 1363 'import "a.dart"; f() { print((() => new C().d)()); }'); | |
| 1364 expect(executable.localFunctions, hasLength(1)); | |
| 1365 expect(executable.localFunctions[0].returnType, isNull); | |
| 1366 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, | |
| 1367 absUri('/b.dart'), 'b.dart', 'D', | |
| 1368 onlyInStrongMode: false); | |
| 1369 if (!skipFullyLinkedData) { | |
| 1370 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); | |
| 1371 } | |
| 1372 } | |
| 1373 | |
| 1320 test_constExpr_binary_add() { | 1374 test_constExpr_binary_add() { |
| 1321 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;'); | 1375 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;'); |
| 1322 _assertUnlinkedConst(variable.constExpr, operators: [ | 1376 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1323 UnlinkedConstOperation.pushInt, | 1377 UnlinkedConstOperation.pushInt, |
| 1324 UnlinkedConstOperation.pushInt, | 1378 UnlinkedConstOperation.pushInt, |
| 1325 UnlinkedConstOperation.add | 1379 UnlinkedConstOperation.add |
| 1326 ], ints: [ | 1380 ], ints: [ |
| 1327 1, | 1381 1, |
| 1328 2 | 1382 2 |
| 1329 ]); | 1383 ]); |
| (...skipping 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5467 expect(linkedReference.dependency, 0); | 5521 expect(linkedReference.dependency, 0); |
| 5468 expect(linkedReference.kind, ReferenceKind.propertyAccessor); | 5522 expect(linkedReference.kind, ReferenceKind.propertyAccessor); |
| 5469 expect(linkedReference.name, 'f='); | 5523 expect(linkedReference.name, 'f='); |
| 5470 expect(linkedReference.numTypeParameters, 0); | 5524 expect(linkedReference.numTypeParameters, 0); |
| 5471 expect(linkedReference.unit, 0); | 5525 expect(linkedReference.unit, 0); |
| 5472 expect(linkedReference.containingReference, isNot(0)); | 5526 expect(linkedReference.containingReference, isNot(0)); |
| 5473 expect(linkedReference.containingReference, lessThan(type.reference)); | 5527 expect(linkedReference.containingReference, lessThan(type.reference)); |
| 5474 checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); | 5528 checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); |
| 5475 } | 5529 } |
| 5476 | 5530 |
| 5531 test_initializer_executable_with_bottom_return_type() { | |
| 5532 // The synthetic executable for `v` has type `() => Bottom`. | |
| 5533 UnlinkedVariable variable = serializeVariableText('int v = null;'); | |
| 5534 expect(variable.initializer.returnType, isNull); | |
| 5535 checkInferredTypeSlot( | |
| 5536 variable.initializer.inferredReturnTypeSlot, null, null, '*bottom*', | |
| 5537 onlyInStrongMode: false); | |
| 5538 } | |
| 5539 | |
| 5540 test_initializer_executable_with_imported_return_type() { | |
| 5541 addNamedSource('/a.dart', 'class C { D d; } class D {}'); | |
| 5542 // The synthetic executable for `v` has type `() => D`; `D` is defined in | |
| 5543 // a library that is imported. Note: `v` is mis-typed as `int` to prevent | |
| 5544 // type propagation, which would complicate the test. | |
| 5545 UnlinkedVariable variable = serializeVariableText( | |
| 5546 'import "a.dart"; int v = new C().d;', | |
| 5547 allowErrors: true); | |
| 5548 expect(variable.initializer.returnType, isNull); | |
| 5549 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, | |
| 5550 absUri('/a.dart'), 'a.dart', 'D', | |
| 5551 onlyInStrongMode: false); | |
| 5552 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); | |
| 5553 } | |
| 5554 | |
| 5555 test_initializer_executable_with_unimported_return_type() { | |
| 5556 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); | |
| 5557 addNamedSource('/b.dart', 'class D {}'); | |
| 5558 // The synthetic executable for `v` has type `() => D`; `D` is defined in | |
| 5559 // a library that is not imported. Note: `v` is mis-typed as `int` to | |
| 5560 // prevent type propagation, which would complicate the test. | |
| 5561 UnlinkedVariable variable = serializeVariableText( | |
| 5562 'import "a.dart"; int v = new C().d;', | |
| 5563 allowErrors: true); | |
| 5564 expect(variable.initializer.returnType, isNull); | |
| 5565 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, | |
| 5566 absUri('/b.dart'), 'b.dart', 'D', | |
| 5567 onlyInStrongMode: false); | |
| 5568 if (!skipFullyLinkedData) { | |
| 5569 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); | |
| 5570 } | |
| 5571 } | |
| 5572 | |
| 5477 test_invalid_prefix_dynamic() { | 5573 test_invalid_prefix_dynamic() { |
| 5478 if (checkAstDerivedData) { | 5574 if (checkAstDerivedData) { |
| 5479 // TODO(paulberry): get this to work properly. | 5575 // TODO(paulberry): get this to work properly. |
| 5480 return; | 5576 return; |
| 5481 } | 5577 } |
| 5482 checkUnresolvedTypeRef( | 5578 checkUnresolvedTypeRef( |
| 5483 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T'); | 5579 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T'); |
| 5484 } | 5580 } |
| 5485 | 5581 |
| 5486 test_invalid_prefix_type_parameter() { | 5582 test_invalid_prefix_type_parameter() { |
| (...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6967 final String absoluteUri; | 7063 final String absoluteUri; |
| 6968 final String relativeUri; | 7064 final String relativeUri; |
| 6969 final int numTypeParameters; | 7065 final int numTypeParameters; |
| 6970 | 7066 |
| 6971 _PrefixExpectation(this.kind, this.name, | 7067 _PrefixExpectation(this.kind, this.name, |
| 6972 {this.inLibraryDefiningUnit: false, | 7068 {this.inLibraryDefiningUnit: false, |
| 6973 this.absoluteUri, | 7069 this.absoluteUri, |
| 6974 this.relativeUri, | 7070 this.relativeUri, |
| 6975 this.numTypeParameters: 0}); | 7071 this.numTypeParameters: 0}); |
| 6976 } | 7072 } |
| OLD | NEW |