| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 * TODO(scheglov) remove [checkAstDerivedDataOverride] once elements-based | 473 * TODO(scheglov) remove [checkAstDerivedDataOverride] once elements-based |
| 474 * serializer can record unresolved information. | 474 * serializer can record unresolved information. |
| 475 */ | 475 */ |
| 476 UnlinkedReference checkReferenceIndex(int referenceIndex, String absoluteUri, | 476 UnlinkedReference checkReferenceIndex(int referenceIndex, String absoluteUri, |
| 477 String relativeUri, String expectedName, | 477 String relativeUri, String expectedName, |
| 478 {ReferenceKind expectedKind: ReferenceKind.classOrEnum, | 478 {ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| 479 int expectedTargetUnit: 0, | 479 int expectedTargetUnit: 0, |
| 480 LinkedUnit linkedSourceUnit, | 480 LinkedUnit linkedSourceUnit, |
| 481 UnlinkedUnit unlinkedSourceUnit, | 481 UnlinkedUnit unlinkedSourceUnit, |
| 482 int numTypeParameters: 0, | 482 int numTypeParameters: 0, |
| 483 bool checkAstDerivedDataOverride: false}) { | 483 bool checkAstDerivedDataOverride: false, |
| 484 int localIndex: 0}) { |
| 484 linkedSourceUnit ??= definingUnit; | 485 linkedSourceUnit ??= definingUnit; |
| 485 unlinkedSourceUnit ??= unlinkedUnits[0]; | 486 unlinkedSourceUnit ??= unlinkedUnits[0]; |
| 486 LinkedReference referenceResolution = | 487 LinkedReference referenceResolution = |
| 487 linkedSourceUnit.references[referenceIndex]; | 488 linkedSourceUnit.references[referenceIndex]; |
| 488 String name; | 489 String name; |
| 489 UnlinkedReference reference; | 490 UnlinkedReference reference; |
| 490 if (referenceIndex < unlinkedSourceUnit.references.length) { | 491 if (referenceIndex < unlinkedSourceUnit.references.length) { |
| 491 // This is an explicit reference, so its name and prefix should be in | 492 // This is an explicit reference, so its name and prefix should be in |
| 492 // [UnlinkedUnit.references]. | 493 // [UnlinkedUnit.references]. |
| 493 expect(referenceResolution.name, isEmpty); | 494 expect(referenceResolution.name, isEmpty); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 519 } else { | 520 } else { |
| 520 if (expectedName == null) { | 521 if (expectedName == null) { |
| 521 expect(name, isEmpty); | 522 expect(name, isEmpty); |
| 522 } else { | 523 } else { |
| 523 expect(name, expectedName); | 524 expect(name, expectedName); |
| 524 } | 525 } |
| 525 } | 526 } |
| 526 expect(referenceResolution.kind, expectedKind); | 527 expect(referenceResolution.kind, expectedKind); |
| 527 expect(referenceResolution.unit, expectedTargetUnit); | 528 expect(referenceResolution.unit, expectedTargetUnit); |
| 528 expect(referenceResolution.numTypeParameters, numTypeParameters); | 529 expect(referenceResolution.numTypeParameters, numTypeParameters); |
| 530 expect(referenceResolution.localIndex, localIndex); |
| 529 return reference; | 531 return reference; |
| 530 } | 532 } |
| 531 | 533 |
| 532 /** | 534 /** |
| 533 * Verify that the given [typeRef] represents a reference to a type declared | 535 * Verify that the given [typeRef] represents a reference to a type declared |
| 534 * in a file reachable via [absoluteUri] and [relativeUri], having name | 536 * in a file reachable via [absoluteUri] and [relativeUri], having name |
| 535 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is | 537 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is |
| 536 * reached via the given prefix. If [allowTypeParameters] is true, allow the | 538 * reached via the given prefix. If [allowTypeParameters] is true, allow the |
| 537 * type reference to supply type parameters. [expectedKind] is the kind of | 539 * type reference to supply type parameters. [expectedKind] is the kind of |
| 538 * object referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer | 540 * object referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 UnlinkedEnum serializeEnumText(String text, [String enumName = 'E']) { | 778 UnlinkedEnum serializeEnumText(String text, [String enumName = 'E']) { |
| 777 serializeLibraryText(text); | 779 serializeLibraryText(text); |
| 778 return findEnum(enumName, failIfAbsent: true); | 780 return findEnum(enumName, failIfAbsent: true); |
| 779 } | 781 } |
| 780 | 782 |
| 781 /** | 783 /** |
| 782 * Serialize the given library [text] and return the summary of the | 784 * Serialize the given library [text] and return the summary of the |
| 783 * executable with the given [executableName]. | 785 * executable with the given [executableName]. |
| 784 */ | 786 */ |
| 785 UnlinkedExecutable serializeExecutableText(String text, | 787 UnlinkedExecutable serializeExecutableText(String text, |
| 786 [String executableName = 'f']) { | 788 {String executableName: 'f', bool allowErrors: false}) { |
| 787 serializeLibraryText(text); | 789 serializeLibraryText(text, allowErrors: allowErrors); |
| 788 return findExecutable(executableName, failIfAbsent: true); | 790 return findExecutable(executableName, failIfAbsent: true); |
| 789 } | 791 } |
| 790 | 792 |
| 791 /** | 793 /** |
| 792 * Serialize the given library [text], then deserialize it and store its | 794 * Serialize the given library [text], then deserialize it and store its |
| 793 * summary in [lib]. | 795 * summary in [lib]. |
| 794 */ | 796 */ |
| 795 void serializeLibraryText(String text, {bool allowErrors: false}); | 797 void serializeLibraryText(String text, {bool allowErrors: false}); |
| 796 | 798 |
| 797 /** | 799 /** |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 UnlinkedExecutable executable = serializeExecutableText( | 1361 UnlinkedExecutable executable = serializeExecutableText( |
| 1360 'import "a.dart"; f() { print((() => new C().d)()); }'); | 1362 'import "a.dart"; f() { print((() => new C().d)()); }'); |
| 1361 expect(executable.localFunctions, hasLength(1)); | 1363 expect(executable.localFunctions, hasLength(1)); |
| 1362 expect(executable.localFunctions[0].returnType, isNull); | 1364 expect(executable.localFunctions[0].returnType, isNull); |
| 1363 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, | 1365 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, |
| 1364 absUri('/a.dart'), 'a.dart', 'D', | 1366 absUri('/a.dart'), 'a.dart', 'D', |
| 1365 onlyInStrongMode: false); | 1367 onlyInStrongMode: false); |
| 1366 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); | 1368 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); |
| 1367 } | 1369 } |
| 1368 | 1370 |
| 1371 test_closure_executable_with_return_type_from_closure() { |
| 1372 if (skipFullyLinkedData) { |
| 1373 return; |
| 1374 } |
| 1375 // The closure has type `() => () => int`, where the `() => int` part refers |
| 1376 // to the nested closure. |
| 1377 UnlinkedExecutable executable = serializeExecutableText(''' |
| 1378 f() { |
| 1379 print(() {}); // force the closure below to have index 1 |
| 1380 print(() => () => 0); |
| 1381 } |
| 1382 '''); |
| 1383 expect(executable.localFunctions, hasLength(2)); |
| 1384 EntityRef closureType = |
| 1385 getTypeRefForSlot(executable.localFunctions[1].inferredReturnTypeSlot); |
| 1386 checkLinkedTypeRef(closureType, null, null, '', |
| 1387 expectedKind: ReferenceKind.function); |
| 1388 int outerClosureIndex = |
| 1389 definingUnit.references[closureType.reference].containingReference; |
| 1390 checkReferenceIndex(outerClosureIndex, null, null, '', |
| 1391 expectedKind: ReferenceKind.function, localIndex: 1); |
| 1392 int topLevelFunctionIndex = |
| 1393 definingUnit.references[outerClosureIndex].containingReference; |
| 1394 checkReferenceIndex(topLevelFunctionIndex, null, null, 'f', |
| 1395 expectedKind: ReferenceKind.topLevelFunction); |
| 1396 expect( |
| 1397 definingUnit.references[topLevelFunctionIndex].containingReference, 0); |
| 1398 } |
| 1399 |
| 1369 test_closure_executable_with_unimported_return_type() { | 1400 test_closure_executable_with_unimported_return_type() { |
| 1370 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); | 1401 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); |
| 1371 addNamedSource('/b.dart', 'class D {}'); | 1402 addNamedSource('/b.dart', 'class D {}'); |
| 1372 // The closure has type `() => D`; `D` is defined in a library that is not | 1403 // The closure has type `() => D`; `D` is defined in a library that is not |
| 1373 // imported. | 1404 // imported. |
| 1374 UnlinkedExecutable executable = serializeExecutableText( | 1405 UnlinkedExecutable executable = serializeExecutableText( |
| 1375 'import "a.dart"; f() { print((() => new C().d)()); }'); | 1406 'import "a.dart"; f() { print((() => new C().d)()); }'); |
| 1376 expect(executable.localFunctions, hasLength(1)); | 1407 expect(executable.localFunctions, hasLength(1)); |
| 1377 expect(executable.localFunctions[0].returnType, isNull); | 1408 expect(executable.localFunctions[0].returnType, isNull); |
| 1378 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, | 1409 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, |
| (...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4022 serializeExecutableText('dynamic f() => null;'); | 4053 serializeExecutableText('dynamic f() => null;'); |
| 4023 checkDynamicTypeRef(executable.returnType); | 4054 checkDynamicTypeRef(executable.returnType); |
| 4024 } | 4055 } |
| 4025 | 4056 |
| 4026 test_executable_function_external() { | 4057 test_executable_function_external() { |
| 4027 UnlinkedExecutable executable = serializeExecutableText('external f();'); | 4058 UnlinkedExecutable executable = serializeExecutableText('external f();'); |
| 4028 expect(executable.isExternal, isTrue); | 4059 expect(executable.isExternal, isTrue); |
| 4029 } | 4060 } |
| 4030 | 4061 |
| 4031 test_executable_function_private() { | 4062 test_executable_function_private() { |
| 4032 serializeExecutableText('_f() {}', '_f'); | 4063 serializeExecutableText('_f() {}', executableName: '_f'); |
| 4033 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 4064 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 4034 } | 4065 } |
| 4035 | 4066 |
| 4036 test_executable_getter() { | 4067 test_executable_getter() { |
| 4037 String text = 'int get f => 1;'; | 4068 String text = 'int get f => 1;'; |
| 4038 UnlinkedExecutable executable = serializeExecutableText(text); | 4069 UnlinkedExecutable executable = serializeExecutableText(text); |
| 4039 expect(executable.kind, UnlinkedExecutableKind.getter); | 4070 expect(executable.kind, UnlinkedExecutableKind.getter); |
| 4040 expect(executable.returnType, isNotNull); | 4071 expect(executable.returnType, isNotNull); |
| 4041 expect(executable.isExternal, isFalse); | 4072 expect(executable.isExternal, isFalse); |
| 4042 expect(executable.nameOffset, text.indexOf('f')); | 4073 expect(executable.nameOffset, text.indexOf('f')); |
| 4043 expect(findVariable('f'), isNull); | 4074 expect(findVariable('f'), isNull); |
| 4044 expect(findExecutable('f='), isNull); | 4075 expect(findExecutable('f='), isNull); |
| 4045 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 4076 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 4046 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 4077 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 4047 ReferenceKind.topLevelPropertyAccessor); | 4078 ReferenceKind.topLevelPropertyAccessor); |
| 4048 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); | 4079 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); |
| 4049 } | 4080 } |
| 4050 | 4081 |
| 4051 test_executable_getter_external() { | 4082 test_executable_getter_external() { |
| 4052 UnlinkedExecutable executable = | 4083 UnlinkedExecutable executable = |
| 4053 serializeExecutableText('external int get f;'); | 4084 serializeExecutableText('external int get f;'); |
| 4054 expect(executable.isExternal, isTrue); | 4085 expect(executable.isExternal, isTrue); |
| 4055 } | 4086 } |
| 4056 | 4087 |
| 4057 test_executable_getter_private() { | 4088 test_executable_getter_private() { |
| 4058 serializeExecutableText('int get _f => 1;', '_f'); | 4089 serializeExecutableText('int get _f => 1;', executableName: '_f'); |
| 4059 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 4090 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 4060 } | 4091 } |
| 4061 | 4092 |
| 4062 test_executable_getter_type() { | 4093 test_executable_getter_type() { |
| 4063 UnlinkedExecutable executable = serializeExecutableText('int get f => 1;'); | 4094 UnlinkedExecutable executable = serializeExecutableText('int get f => 1;'); |
| 4064 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'int'); | 4095 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'int'); |
| 4065 expect(executable.parameters, isEmpty); | 4096 expect(executable.parameters, isEmpty); |
| 4066 } | 4097 } |
| 4067 | 4098 |
| 4068 test_executable_getter_type_implicit() { | 4099 test_executable_getter_type_implicit() { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4228 } | 4259 } |
| 4229 } | 4260 } |
| 4230 | 4261 |
| 4231 test_executable_localVariables_inTopLevelGetter() { | 4262 test_executable_localVariables_inTopLevelGetter() { |
| 4232 String code = r''' | 4263 String code = r''' |
| 4233 get g { // 1 | 4264 get g { // 1 |
| 4234 int v; | 4265 int v; |
| 4235 f() {} | 4266 f() {} |
| 4236 } // 2 | 4267 } // 2 |
| 4237 '''; | 4268 '''; |
| 4238 UnlinkedExecutable executable = serializeExecutableText(code, 'g'); | 4269 UnlinkedExecutable executable = |
| 4270 serializeExecutableText(code, executableName: 'g'); |
| 4239 { | 4271 { |
| 4240 List<UnlinkedExecutable> functions = executable.localFunctions; | 4272 List<UnlinkedExecutable> functions = executable.localFunctions; |
| 4241 expect(functions, hasLength(1)); | 4273 expect(functions, hasLength(1)); |
| 4242 UnlinkedExecutable f = functions.singleWhere((v) => v.name == 'f'); | 4274 UnlinkedExecutable f = functions.singleWhere((v) => v.name == 'f'); |
| 4243 _assertExecutableVisible(code, f, '{ // 1', '} // 2'); | 4275 _assertExecutableVisible(code, f, '{ // 1', '} // 2'); |
| 4244 } | 4276 } |
| 4245 { | 4277 { |
| 4246 List<UnlinkedVariable> variables = executable.localVariables; | 4278 List<UnlinkedVariable> variables = executable.localVariables; |
| 4247 expect(variables, hasLength(1)); | 4279 expect(variables, hasLength(1)); |
| 4248 UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v'); | 4280 UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v'); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4598 expect(executable.returnType, isNull); | 4630 expect(executable.returnType, isNull); |
| 4599 } | 4631 } |
| 4600 | 4632 |
| 4601 test_executable_return_type_void() { | 4633 test_executable_return_type_void() { |
| 4602 UnlinkedExecutable executable = serializeExecutableText('void f() {}'); | 4634 UnlinkedExecutable executable = serializeExecutableText('void f() {}'); |
| 4603 checkVoidTypeRef(executable.returnType); | 4635 checkVoidTypeRef(executable.returnType); |
| 4604 } | 4636 } |
| 4605 | 4637 |
| 4606 test_executable_setter() { | 4638 test_executable_setter() { |
| 4607 String text = 'void set f(value) {}'; | 4639 String text = 'void set f(value) {}'; |
| 4608 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); | 4640 UnlinkedExecutable executable = |
| 4641 serializeExecutableText(text, executableName: 'f='); |
| 4609 expect(executable.kind, UnlinkedExecutableKind.setter); | 4642 expect(executable.kind, UnlinkedExecutableKind.setter); |
| 4610 expect(executable.returnType, isNotNull); | 4643 expect(executable.returnType, isNotNull); |
| 4611 expect(executable.isExternal, isFalse); | 4644 expect(executable.isExternal, isFalse); |
| 4612 expect(executable.nameOffset, text.indexOf('f')); | 4645 expect(executable.nameOffset, text.indexOf('f')); |
| 4613 expect(findVariable('f'), isNull); | 4646 expect(findVariable('f'), isNull); |
| 4614 expect(findExecutable('f'), isNull); | 4647 expect(findExecutable('f'), isNull); |
| 4615 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 4648 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 4616 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 4649 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 4617 ReferenceKind.topLevelPropertyAccessor); | 4650 ReferenceKind.topLevelPropertyAccessor); |
| 4618 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); | 4651 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); |
| 4619 } | 4652 } |
| 4620 | 4653 |
| 4621 test_executable_setter_external() { | 4654 test_executable_setter_external() { |
| 4622 UnlinkedExecutable executable = | 4655 UnlinkedExecutable executable = serializeExecutableText( |
| 4623 serializeExecutableText('external void set f(value);', 'f='); | 4656 'external void set f(value);', |
| 4657 executableName: 'f='); |
| 4624 expect(executable.isExternal, isTrue); | 4658 expect(executable.isExternal, isTrue); |
| 4625 } | 4659 } |
| 4626 | 4660 |
| 4627 test_executable_setter_implicit_return() { | 4661 test_executable_setter_implicit_return() { |
| 4628 UnlinkedExecutable executable = | 4662 UnlinkedExecutable executable = |
| 4629 serializeExecutableText('set f(value) {}', 'f='); | 4663 serializeExecutableText('set f(value) {}', executableName: 'f='); |
| 4630 expect(executable.returnType, isNull); | 4664 expect(executable.returnType, isNull); |
| 4631 } | 4665 } |
| 4632 | 4666 |
| 4633 test_executable_setter_private() { | 4667 test_executable_setter_private() { |
| 4634 serializeExecutableText('void set _f(value) {}', '_f='); | 4668 serializeExecutableText('void set _f(value) {}', executableName: '_f='); |
| 4635 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 4669 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 4636 } | 4670 } |
| 4637 | 4671 |
| 4638 test_executable_setter_type() { | 4672 test_executable_setter_type() { |
| 4639 UnlinkedExecutable executable = | 4673 UnlinkedExecutable executable = serializeExecutableText( |
| 4640 serializeExecutableText('void set f(int value) {}', 'f='); | 4674 'void set f(int value) {}', |
| 4675 executableName: 'f='); |
| 4641 checkVoidTypeRef(executable.returnType); | 4676 checkVoidTypeRef(executable.returnType); |
| 4642 expect(executable.parameters, hasLength(1)); | 4677 expect(executable.parameters, hasLength(1)); |
| 4643 expect(executable.parameters[0].name, 'value'); | 4678 expect(executable.parameters[0].name, 'value'); |
| 4644 checkTypeRef( | 4679 checkTypeRef( |
| 4645 executable.parameters[0].type, 'dart:core', 'dart:core', 'int'); | 4680 executable.parameters[0].type, 'dart:core', 'dart:core', 'int'); |
| 4646 } | 4681 } |
| 4647 | 4682 |
| 4648 test_executable_static() { | 4683 test_executable_static() { |
| 4649 UnlinkedExecutable executable = | 4684 UnlinkedExecutable executable = |
| 4650 serializeClassText('class C { static f() {} }').executables[0]; | 4685 serializeClassText('class C { static f() {} }').executables[0]; |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5567 UnlinkedVariable variable = serializeVariableText( | 5602 UnlinkedVariable variable = serializeVariableText( |
| 5568 'import "a.dart"; int v = new C().d;', | 5603 'import "a.dart"; int v = new C().d;', |
| 5569 allowErrors: true); | 5604 allowErrors: true); |
| 5570 expect(variable.initializer.returnType, isNull); | 5605 expect(variable.initializer.returnType, isNull); |
| 5571 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, | 5606 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, |
| 5572 absUri('/a.dart'), 'a.dart', 'D', | 5607 absUri('/a.dart'), 'a.dart', 'D', |
| 5573 onlyInStrongMode: false); | 5608 onlyInStrongMode: false); |
| 5574 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); | 5609 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); |
| 5575 } | 5610 } |
| 5576 | 5611 |
| 5612 test_initializer_executable_with_return_type_from_closure() { |
| 5613 if (skipFullyLinkedData) { |
| 5614 return; |
| 5615 } |
| 5616 // The synthetic executable for `v` has type `() => () => int`, where the |
| 5617 // `() => int` part refers to the closure declared inside the initializer |
| 5618 // for v. Note: `v` is mis-typed as `int` to prevent type propagation, |
| 5619 // which would complicate the test. |
| 5620 UnlinkedVariable variable = |
| 5621 serializeVariableText('int v = () => 0;', allowErrors: true); |
| 5622 EntityRef closureType = |
| 5623 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); |
| 5624 checkLinkedTypeRef(closureType, null, null, '', |
| 5625 expectedKind: ReferenceKind.function); |
| 5626 int initializerIndex = |
| 5627 definingUnit.references[closureType.reference].containingReference; |
| 5628 checkReferenceIndex(initializerIndex, null, null, '', |
| 5629 expectedKind: ReferenceKind.function); |
| 5630 int variableIndex = |
| 5631 definingUnit.references[initializerIndex].containingReference; |
| 5632 checkReferenceIndex(variableIndex, null, null, 'v', |
| 5633 expectedKind: ReferenceKind.topLevelPropertyAccessor); |
| 5634 expect(definingUnit.references[variableIndex].containingReference, 0); |
| 5635 } |
| 5636 |
| 5637 test_initializer_executable_with_return_type_from_closure_field() { |
| 5638 if (skipFullyLinkedData) { |
| 5639 return; |
| 5640 } |
| 5641 // The synthetic executable for `v` has type `() => () => int`, where the |
| 5642 // `() => int` part refers to the closure declared inside the initializer |
| 5643 // for v. Note: `v` is mis-typed as `int` to prevent type propagation, |
| 5644 // which would complicate the test. |
| 5645 UnlinkedClass cls = serializeClassText( |
| 5646 ''' |
| 5647 class C { |
| 5648 int v = () => 0; |
| 5649 } |
| 5650 ''', |
| 5651 allowErrors: true); |
| 5652 UnlinkedVariable variable = cls.fields[0]; |
| 5653 EntityRef closureType = |
| 5654 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); |
| 5655 checkLinkedTypeRef(closureType, null, null, '', |
| 5656 expectedKind: ReferenceKind.function); |
| 5657 int initializerIndex = |
| 5658 definingUnit.references[closureType.reference].containingReference; |
| 5659 checkReferenceIndex(initializerIndex, null, null, '', |
| 5660 expectedKind: ReferenceKind.function); |
| 5661 int variableIndex = |
| 5662 definingUnit.references[initializerIndex].containingReference; |
| 5663 checkReferenceIndex(variableIndex, null, null, 'v', |
| 5664 expectedKind: ReferenceKind.propertyAccessor); |
| 5665 int classIndex = definingUnit.references[variableIndex].containingReference; |
| 5666 checkReferenceIndex(classIndex, null, null, 'C'); |
| 5667 expect(definingUnit.references[classIndex].containingReference, 0); |
| 5668 } |
| 5669 |
| 5670 test_initializer_executable_with_return_type_from_closure_local() { |
| 5671 if (skipFullyLinkedData) { |
| 5672 return; |
| 5673 } |
| 5674 // The synthetic executable for `v` has type `() => () => int`, where the |
| 5675 // `() => int` part refers to the closure declared inside the initializer |
| 5676 // for v. Note: `v` is mis-typed as `int` to prevent type propagation, |
| 5677 // which would complicate the test. |
| 5678 UnlinkedExecutable executable = serializeExecutableText( |
| 5679 ''' |
| 5680 void f() { |
| 5681 int u = 0; // force the variable below to have index 1 |
| 5682 int v = () => 0; |
| 5683 }''', |
| 5684 allowErrors: true); |
| 5685 UnlinkedVariable variable = executable.localVariables[1]; |
| 5686 EntityRef closureType = |
| 5687 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); |
| 5688 checkLinkedTypeRef(closureType, null, null, '', |
| 5689 expectedKind: ReferenceKind.function); |
| 5690 int initializerIndex = |
| 5691 definingUnit.references[closureType.reference].containingReference; |
| 5692 checkReferenceIndex(initializerIndex, null, null, '', |
| 5693 expectedKind: ReferenceKind.function); |
| 5694 int variableIndex = |
| 5695 definingUnit.references[initializerIndex].containingReference; |
| 5696 checkReferenceIndex(variableIndex, null, null, 'v', |
| 5697 expectedKind: ReferenceKind.variable, localIndex: 1); |
| 5698 int topLevelFunctionIndex = |
| 5699 definingUnit.references[variableIndex].containingReference; |
| 5700 checkReferenceIndex(topLevelFunctionIndex, null, null, 'f', |
| 5701 expectedKind: ReferenceKind.topLevelFunction); |
| 5702 expect( |
| 5703 definingUnit.references[topLevelFunctionIndex].containingReference, 0); |
| 5704 } |
| 5705 |
| 5577 test_initializer_executable_with_unimported_return_type() { | 5706 test_initializer_executable_with_unimported_return_type() { |
| 5578 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); | 5707 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); |
| 5579 addNamedSource('/b.dart', 'class D {}'); | 5708 addNamedSource('/b.dart', 'class D {}'); |
| 5580 // The synthetic executable for `v` has type `() => D`; `D` is defined in | 5709 // The synthetic executable for `v` has type `() => D`; `D` is defined in |
| 5581 // a library that is not imported. Note: `v` is mis-typed as `int` to | 5710 // a library that is not imported. Note: `v` is mis-typed as `int` to |
| 5582 // prevent type propagation, which would complicate the test. | 5711 // prevent type propagation, which would complicate the test. |
| 5583 UnlinkedVariable variable = serializeVariableText( | 5712 UnlinkedVariable variable = serializeVariableText( |
| 5584 'import "a.dart"; int v = new C().d;', | 5713 'import "a.dart"; int v = new C().d;', |
| 5585 allowErrors: true); | 5714 allowErrors: true); |
| 5586 expect(variable.initializer.returnType, isNull); | 5715 expect(variable.initializer.returnType, isNull); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5863 serializeExecutableText('const a = null; @a f() {}').annotations); | 5992 serializeExecutableText('const a = null; @a f() {}').annotations); |
| 5864 } | 5993 } |
| 5865 | 5994 |
| 5866 test_metadata_functionDeclaration_getter() { | 5995 test_metadata_functionDeclaration_getter() { |
| 5867 checkAnnotationA( | 5996 checkAnnotationA( |
| 5868 serializeExecutableText('const a = null; @a get f => null;') | 5997 serializeExecutableText('const a = null; @a get f => null;') |
| 5869 .annotations); | 5998 .annotations); |
| 5870 } | 5999 } |
| 5871 | 6000 |
| 5872 test_metadata_functionDeclaration_setter() { | 6001 test_metadata_functionDeclaration_setter() { |
| 5873 checkAnnotationA( | 6002 checkAnnotationA(serializeExecutableText( |
| 5874 serializeExecutableText('const a = null; @a set f(value) {}', 'f=') | 6003 'const a = null; @a set f(value) {}', |
| 5875 .annotations); | 6004 executableName: 'f=') |
| 6005 .annotations); |
| 5876 } | 6006 } |
| 5877 | 6007 |
| 5878 test_metadata_functionTypeAlias() { | 6008 test_metadata_functionTypeAlias() { |
| 5879 checkAnnotationA( | 6009 checkAnnotationA( |
| 5880 serializeTypedefText('const a = null; @a typedef F();').annotations); | 6010 serializeTypedefText('const a = null; @a typedef F();').annotations); |
| 5881 } | 6011 } |
| 5882 | 6012 |
| 5883 test_metadata_functionTypedFormalParameter() { | 6013 test_metadata_functionTypedFormalParameter() { |
| 5884 checkAnnotationA(serializeExecutableText('const a = null; f(@a g()) {}') | 6014 checkAnnotationA(serializeExecutableText('const a = null; f(@a g()) {}') |
| 5885 .parameters[0] | 6015 .parameters[0] |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6217 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C'); | 6347 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C'); |
| 6218 } | 6348 } |
| 6219 | 6349 |
| 6220 test_setter_documented() { | 6350 test_setter_documented() { |
| 6221 String text = ''' | 6351 String text = ''' |
| 6222 // Extra comment so doc comment offset != 0 | 6352 // Extra comment so doc comment offset != 0 |
| 6223 /** | 6353 /** |
| 6224 * Docs | 6354 * Docs |
| 6225 */ | 6355 */ |
| 6226 void set f(value) {}'''; | 6356 void set f(value) {}'''; |
| 6227 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); | 6357 UnlinkedExecutable executable = |
| 6358 serializeExecutableText(text, executableName: 'f='); |
| 6228 expect(executable.documentationComment, isNotNull); | 6359 expect(executable.documentationComment, isNotNull); |
| 6229 checkDocumentationComment(executable.documentationComment, text); | 6360 checkDocumentationComment(executable.documentationComment, text); |
| 6230 } | 6361 } |
| 6231 | 6362 |
| 6232 test_setter_inferred_type_nonstatic_explicit_param() { | 6363 test_setter_inferred_type_nonstatic_explicit_param() { |
| 6233 UnlinkedExecutable f = serializeClassText( | 6364 UnlinkedExecutable f = serializeClassText( |
| 6234 'class C extends D { void set f(num value) {} }' | 6365 'class C extends D { void set f(num value) {} }' |
| 6235 ' abstract class D { void set f(int value); }', | 6366 ' abstract class D { void set f(int value); }', |
| 6236 className: 'C') | 6367 className: 'C') |
| 6237 .executables[0]; | 6368 .executables[0]; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6272 | 6403 |
| 6273 test_setter_inferred_type_static_implicit_return() { | 6404 test_setter_inferred_type_static_implicit_return() { |
| 6274 UnlinkedExecutable f = | 6405 UnlinkedExecutable f = |
| 6275 serializeClassText('class C { static set f(int value) {} }') | 6406 serializeClassText('class C { static set f(int value) {} }') |
| 6276 .executables[0]; | 6407 .executables[0]; |
| 6277 expect(f.inferredReturnTypeSlot, 0); | 6408 expect(f.inferredReturnTypeSlot, 0); |
| 6278 } | 6409 } |
| 6279 | 6410 |
| 6280 test_setter_inferred_type_top_level_implicit_param() { | 6411 test_setter_inferred_type_top_level_implicit_param() { |
| 6281 UnlinkedExecutable f = | 6412 UnlinkedExecutable f = |
| 6282 serializeExecutableText('void set f(value) {}', 'f='); | 6413 serializeExecutableText('void set f(value) {}', executableName: 'f='); |
| 6283 expect(f.parameters[0].inferredTypeSlot, 0); | 6414 expect(f.parameters[0].inferredTypeSlot, 0); |
| 6284 } | 6415 } |
| 6285 | 6416 |
| 6286 test_setter_inferred_type_top_level_implicit_return() { | 6417 test_setter_inferred_type_top_level_implicit_return() { |
| 6287 UnlinkedExecutable f = serializeExecutableText('set f(int value) {}', 'f='); | 6418 UnlinkedExecutable f = |
| 6419 serializeExecutableText('set f(int value) {}', executableName: 'f='); |
| 6288 expect(f.inferredReturnTypeSlot, 0); | 6420 expect(f.inferredReturnTypeSlot, 0); |
| 6289 } | 6421 } |
| 6290 | 6422 |
| 6291 test_slot_reuse() { | 6423 test_slot_reuse() { |
| 6292 // Different compilation units have independent notions of slot id, so slot | 6424 // Different compilation units have independent notions of slot id, so slot |
| 6293 // ids should be reused. | 6425 // ids should be reused. |
| 6294 addNamedSource('/a.dart', 'part of foo; final v = 0;'); | 6426 addNamedSource('/a.dart', 'part of foo; final v = 0;'); |
| 6295 serializeLibraryText('library foo; part "a.dart"; final w = 0;'); | 6427 serializeLibraryText('library foo; part "a.dart"; final w = 0;'); |
| 6296 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1); | 6428 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1); |
| 6297 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1); | 6429 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1); |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7094 final String absoluteUri; | 7226 final String absoluteUri; |
| 7095 final String relativeUri; | 7227 final String relativeUri; |
| 7096 final int numTypeParameters; | 7228 final int numTypeParameters; |
| 7097 | 7229 |
| 7098 _PrefixExpectation(this.kind, this.name, | 7230 _PrefixExpectation(this.kind, this.name, |
| 7099 {this.inLibraryDefiningUnit: false, | 7231 {this.inLibraryDefiningUnit: false, |
| 7100 this.absoluteUri, | 7232 this.absoluteUri, |
| 7101 this.relativeUri, | 7233 this.relativeUri, |
| 7102 this.numTypeParameters: 0}); | 7234 this.numTypeParameters: 0}); |
| 7103 } | 7235 } |
| OLD | NEW |