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/error/listener.dart'; | 9 import 'package:analyzer/error/listener.dart'; |
10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 result = executable; | 708 result = executable; |
709 } | 709 } |
710 } | 710 } |
711 if (result == null && failIfAbsent) { | 711 if (result == null && failIfAbsent) { |
712 fail('Executable $executableName not found in serialized output'); | 712 fail('Executable $executableName not found in serialized output'); |
713 } | 713 } |
714 return result; | 714 return result; |
715 } | 715 } |
716 | 716 |
717 /** | 717 /** |
| 718 * Find the parameter with the given [name] in [parameters]. |
| 719 */ |
| 720 UnlinkedParam findParameter(List<UnlinkedParam> parameters, String name) { |
| 721 UnlinkedParam result; |
| 722 for (UnlinkedParam parameter in parameters) { |
| 723 if (parameter.name == name) { |
| 724 if (result != null) { |
| 725 fail('Duplicate parameter $name'); |
| 726 } |
| 727 result = parameter; |
| 728 } |
| 729 } |
| 730 if (result == null) { |
| 731 fail('Parameter $name not found'); |
| 732 } |
| 733 return result; |
| 734 } |
| 735 |
| 736 /** |
718 * Find the typedef with the given [typedefName] in the summary, and return | 737 * Find the typedef with the given [typedefName] in the summary, and return |
719 * its [UnlinkedTypedef] data structure. If [unit] is not given, the typedef | 738 * its [UnlinkedTypedef] data structure. If [unit] is not given, the typedef |
720 * is looked for in the defining compilation unit. | 739 * is looked for in the defining compilation unit. |
721 */ | 740 */ |
722 UnlinkedTypedef findTypedef(String typedefName, | 741 UnlinkedTypedef findTypedef(String typedefName, |
723 {bool failIfAbsent: false, UnlinkedUnit unit}) { | 742 {bool failIfAbsent: false, UnlinkedUnit unit}) { |
724 unit ??= unlinkedUnits[0]; | 743 unit ??= unlinkedUnits[0]; |
725 UnlinkedTypedef result; | 744 UnlinkedTypedef result; |
726 for (UnlinkedTypedef type in unit.typedefs) { | 745 for (UnlinkedTypedef type in unit.typedefs) { |
727 if (type.name == typedefName) { | 746 if (type.name == typedefName) { |
(...skipping 4643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5371 f() { | 5390 f() { |
5372 foo(p: 42); | 5391 foo(p: 42); |
5373 } | 5392 } |
5374 foo({int p}) {} | 5393 foo({int p}) {} |
5375 '''; | 5394 '''; |
5376 UnlinkedExecutable executable = serializeExecutableText(code); | 5395 UnlinkedExecutable executable = serializeExecutableText(code); |
5377 List<UnlinkedLabel> labels = executable.localLabels; | 5396 List<UnlinkedLabel> labels = executable.localLabels; |
5378 expect(labels, isEmpty); | 5397 expect(labels, isEmpty); |
5379 } | 5398 } |
5380 | 5399 |
5381 test_executable_localVariables_catch() { | |
5382 String code = r''' | |
5383 var v = ( | |
5384 () { // 1 | |
5385 try { | |
5386 throw 42; | |
5387 } on int catch (e, st) { // 2 | |
5388 print(e); | |
5389 print(st); | |
5390 } // 3 | |
5391 } // 4 | |
5392 ); | |
5393 '''; | |
5394 UnlinkedExecutable executable = | |
5395 serializeVariableText(code).initializer.localFunctions[0]; | |
5396 List<UnlinkedVariable> variables = executable.localVariables; | |
5397 expect(variables, hasLength(2)); | |
5398 { | |
5399 UnlinkedVariable e = variables.singleWhere((v) => v.name == 'e'); | |
5400 _assertVariableVisible(code, e, 'on int catch (', '} // 3'); | |
5401 checkTypeRef(e.type, 'dart:core', 'int'); | |
5402 } | |
5403 { | |
5404 UnlinkedVariable st = variables.singleWhere((v) => v.name == 'st'); | |
5405 _assertVariableVisible(code, st, 'on int catch (', '} // 3'); | |
5406 } | |
5407 } | |
5408 | |
5409 test_executable_localVariables_catch_noVariables() { | |
5410 String code = r''' | |
5411 f() { | |
5412 try { | |
5413 throw 42; | |
5414 } on int {} | |
5415 } | |
5416 '''; | |
5417 UnlinkedExecutable executable = serializeExecutableText(code); | |
5418 List<UnlinkedVariable> variables = executable.localVariables; | |
5419 expect(variables, isEmpty); | |
5420 } | |
5421 | |
5422 test_executable_localVariables_empty() { | |
5423 UnlinkedExecutable executable = serializeExecutableText(r''' | |
5424 f() { | |
5425 } | |
5426 '''); | |
5427 expect(executable.localVariables, isEmpty); | |
5428 } | |
5429 | |
5430 test_executable_localVariables_forEachLoop() { | |
5431 String code = r''' | |
5432 var v = (() { | |
5433 f() { // 1 | |
5434 for (int i in <int>[]) { // 2 | |
5435 print(i); | |
5436 } // 3 | |
5437 } // 4 | |
5438 }); | |
5439 '''; | |
5440 UnlinkedExecutable executable = serializeVariableText(code) | |
5441 .initializer | |
5442 .localFunctions[0] | |
5443 .localFunctions[0]; | |
5444 List<UnlinkedVariable> variables = executable.localVariables; | |
5445 expect(variables, hasLength(1)); | |
5446 { | |
5447 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); | |
5448 _assertVariableVisible(code, i, 'for', '} // 3'); | |
5449 checkTypeRef(i.type, 'dart:core', 'int'); | |
5450 } | |
5451 } | |
5452 | |
5453 test_executable_localVariables_forEachLoop_outside() { | |
5454 String code = r''' | |
5455 var v = (() { | |
5456 f() { // 1 | |
5457 int i; | |
5458 for (i in <int>[]) { | |
5459 print(i); | |
5460 } | |
5461 } // 4 | |
5462 }); | |
5463 '''; | |
5464 UnlinkedExecutable executable = serializeVariableText(code) | |
5465 .initializer | |
5466 .localFunctions[0] | |
5467 .localFunctions[0]; | |
5468 List<UnlinkedVariable> variables = executable.localVariables; | |
5469 expect(variables, hasLength(1)); | |
5470 { | |
5471 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); | |
5472 _assertVariableVisible(code, i, '{ // 1', '} // 4'); | |
5473 checkTypeRef(i.type, 'dart:core', 'int'); | |
5474 } | |
5475 } | |
5476 | |
5477 test_executable_localVariables_forLoop() { | |
5478 String code = r''' | |
5479 var v = (() { | |
5480 f() { // 1 | |
5481 for (int i = 0, j = 0; i < 10; i++, j++) { // 2 | |
5482 print(i); | |
5483 } // 3 | |
5484 } // 4 | |
5485 }); | |
5486 '''; | |
5487 UnlinkedExecutable executable = serializeVariableText(code) | |
5488 .initializer | |
5489 .localFunctions[0] | |
5490 .localFunctions[0]; | |
5491 List<UnlinkedVariable> variables = executable.localVariables; | |
5492 expect(variables, hasLength(2)); | |
5493 { | |
5494 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); | |
5495 _assertVariableVisible(code, i, 'for', '} // 3'); | |
5496 checkTypeRef(i.type, 'dart:core', 'int'); | |
5497 } | |
5498 { | |
5499 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'j'); | |
5500 _assertVariableVisible(code, i, 'for', '} // 3'); | |
5501 checkTypeRef(i.type, 'dart:core', 'int'); | |
5502 } | |
5503 } | |
5504 | |
5505 test_executable_localVariables_forLoop_noVariables() { | |
5506 String code = r''' | |
5507 var v = (() { | |
5508 f() { | |
5509 for (; true;) {} | |
5510 } | |
5511 }); | |
5512 '''; | |
5513 UnlinkedExecutable executable = serializeVariableText(code) | |
5514 .initializer | |
5515 .localFunctions[0] | |
5516 .localFunctions[0]; | |
5517 List<UnlinkedVariable> variables = executable.localVariables; | |
5518 expect(variables, isEmpty); | |
5519 } | |
5520 | |
5521 test_executable_localVariables_inConstructor() { | |
5522 String code = r''' | |
5523 class C { | |
5524 C() { | |
5525 int v; | |
5526 } | |
5527 } | |
5528 '''; | |
5529 UnlinkedExecutable executable = | |
5530 findExecutable('', executables: serializeClassText(code).executables); | |
5531 List<UnlinkedVariable> variables = executable.localVariables; | |
5532 expect(variables, isEmpty); | |
5533 } | |
5534 | |
5535 test_executable_localVariables_inLocalFunctions() { | |
5536 String code = r''' | |
5537 var v = (() { | |
5538 f() { | |
5539 f1() { // 1 | |
5540 int v1 = 1; | |
5541 } // 2 | |
5542 f2() { // 3 | |
5543 int v1 = 1; | |
5544 f3() { // 4 | |
5545 int v2 = 1; | |
5546 } // 5 | |
5547 } // 6 | |
5548 } // 7 | |
5549 }); | |
5550 '''; | |
5551 UnlinkedExecutable executable = serializeVariableText(code) | |
5552 .initializer | |
5553 .localFunctions[0] | |
5554 .localFunctions[0]; | |
5555 List<UnlinkedExecutable> functions = executable.localFunctions; | |
5556 expect(functions, hasLength(2)); | |
5557 // f - f1 | |
5558 { | |
5559 UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1'); | |
5560 List<UnlinkedVariable> variables = f1.localVariables; | |
5561 expect(variables, hasLength(1)); | |
5562 // f1 - v1 | |
5563 UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1'); | |
5564 _assertVariableVisible(code, v1, '{ // 1', '} // 2'); | |
5565 checkTypeRef(v1.type, 'dart:core', 'int'); | |
5566 } | |
5567 // f - f2 | |
5568 { | |
5569 UnlinkedExecutable f2 = functions.singleWhere((v) => v.name == 'f2'); | |
5570 List<UnlinkedVariable> variables2 = f2.localVariables; | |
5571 List<UnlinkedExecutable> functions2 = f2.localFunctions; | |
5572 expect(variables2, hasLength(1)); | |
5573 expect(functions2, hasLength(1)); | |
5574 // f - f2 - v1 | |
5575 UnlinkedVariable v1 = variables2.singleWhere((v) => v.name == 'v1'); | |
5576 _assertVariableVisible(code, v1, '{ // 3', '} // 6'); | |
5577 checkTypeRef(v1.type, 'dart:core', 'int'); | |
5578 // f - f2 - f3 | |
5579 UnlinkedExecutable f3 = functions2.singleWhere((v) => v.name == 'f3'); | |
5580 _assertExecutableVisible(code, f3, '{ // 3', '} // 6'); | |
5581 List<UnlinkedVariable> variables3 = f3.localVariables; | |
5582 List<UnlinkedExecutable> functions3 = f3.localFunctions; | |
5583 expect(variables3, hasLength(1)); | |
5584 expect(functions3, hasLength(0)); | |
5585 // f - f3 - v2 | |
5586 UnlinkedVariable v2 = variables3.singleWhere((v) => v.name == 'v2'); | |
5587 _assertVariableVisible(code, v2, '{ // 4', '} // 5'); | |
5588 checkTypeRef(v2.type, 'dart:core', 'int'); | |
5589 } | |
5590 } | |
5591 | |
5592 test_executable_localVariables_inMethod() { | |
5593 String code = r''' | |
5594 class C { | |
5595 m() { | |
5596 int v; | |
5597 f() {} | |
5598 } | |
5599 } | |
5600 '''; | |
5601 UnlinkedExecutable executable = | |
5602 findExecutable('m', executables: serializeClassText(code).executables); | |
5603 expect(executable.localFunctions, isEmpty); | |
5604 expect(executable.localVariables, isEmpty); | |
5605 } | |
5606 | |
5607 test_executable_localVariables_inTopLevelFunction() { | |
5608 String code = r''' | |
5609 f() { | |
5610 int v1 = 1; | |
5611 { | |
5612 int v2 = 2; | |
5613 } | |
5614 var v3 = 3; | |
5615 } | |
5616 '''; | |
5617 UnlinkedExecutable executable = serializeExecutableText(code); | |
5618 List<UnlinkedVariable> variables = executable.localVariables; | |
5619 expect(variables, isEmpty); | |
5620 } | |
5621 | |
5622 test_executable_localVariables_inTopLevelGetter() { | |
5623 String code = r''' | |
5624 get g { // 1 | |
5625 int v; | |
5626 f() {} | |
5627 } // 2 | |
5628 '''; | |
5629 UnlinkedExecutable executable = | |
5630 serializeExecutableText(code, executableName: 'g'); | |
5631 expect(executable.localFunctions, isEmpty); | |
5632 expect(executable.localVariables, isEmpty); | |
5633 } | |
5634 | |
5635 test_executable_member_function() { | 5400 test_executable_member_function() { |
5636 UnlinkedExecutable executable = findExecutable('f', | 5401 UnlinkedExecutable executable = findExecutable('f', |
5637 executables: serializeClassText('class C { f() {} }').executables); | 5402 executables: serializeClassText('class C { f() {} }').executables); |
5638 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); | 5403 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
5639 expect(executable.returnType, isNull); | 5404 expect(executable.returnType, isNull); |
5640 expect(executable.isAsynchronous, isFalse); | 5405 expect(executable.isAsynchronous, isFalse); |
5641 expect(executable.isExternal, isFalse); | 5406 expect(executable.isExternal, isFalse); |
5642 expect(executable.isGenerator, isFalse); | 5407 expect(executable.isGenerator, isFalse); |
5643 if (includeInformative) { | 5408 if (includeInformative) { |
5644 expect(executable.visibleOffset, 0); | 5409 expect(executable.visibleOffset, 0); |
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8705 expectedKind: ReferenceKind.function); | 8470 expectedKind: ReferenceKind.function); |
8706 int variableIndex = | 8471 int variableIndex = |
8707 definingUnit.references[initializerIndex].containingReference; | 8472 definingUnit.references[initializerIndex].containingReference; |
8708 checkReferenceIndex(variableIndex, null, 'v', | 8473 checkReferenceIndex(variableIndex, null, 'v', |
8709 expectedKind: ReferenceKind.propertyAccessor); | 8474 expectedKind: ReferenceKind.propertyAccessor); |
8710 int classIndex = definingUnit.references[variableIndex].containingReference; | 8475 int classIndex = definingUnit.references[variableIndex].containingReference; |
8711 checkReferenceIndex(classIndex, null, 'C'); | 8476 checkReferenceIndex(classIndex, null, 'C'); |
8712 expect(definingUnit.references[classIndex].containingReference, 0); | 8477 expect(definingUnit.references[classIndex].containingReference, 0); |
8713 } | 8478 } |
8714 | 8479 |
8715 test_initializer_executable_with_return_type_from_closure_local() { | |
8716 if (skipFullyLinkedData) { | |
8717 return; | |
8718 } | |
8719 // The synthetic executable for `v` has type `() => () => int`, where the | |
8720 // `() => int` part refers to the closure declared inside the initializer | |
8721 // for v. Note: `v` is mis-typed as `int` to prevent type propagation, | |
8722 // which would complicate the test. | |
8723 UnlinkedExecutable executable = serializeExecutableText( | |
8724 ''' | |
8725 void f() { | |
8726 int u = 0; // force the variable below to have index 1 | |
8727 int v = () => 0; | |
8728 }''', | |
8729 allowErrors: true); | |
8730 UnlinkedVariable variable = executable.localVariables[1]; | |
8731 EntityRef closureType = | |
8732 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); | |
8733 checkLinkedTypeRef(closureType, null, '', | |
8734 expectedKind: ReferenceKind.function); | |
8735 int initializerIndex = | |
8736 definingUnit.references[closureType.reference].containingReference; | |
8737 checkReferenceIndex(initializerIndex, null, '', | |
8738 expectedKind: ReferenceKind.function); | |
8739 int variableIndex = | |
8740 definingUnit.references[initializerIndex].containingReference; | |
8741 checkReferenceIndex(variableIndex, null, 'v', | |
8742 expectedKind: ReferenceKind.variable, localIndex: 1); | |
8743 int topLevelFunctionIndex = | |
8744 definingUnit.references[variableIndex].containingReference; | |
8745 checkReferenceIndex(topLevelFunctionIndex, null, 'f', | |
8746 expectedKind: ReferenceKind.topLevelFunction); | |
8747 expect( | |
8748 definingUnit.references[topLevelFunctionIndex].containingReference, 0); | |
8749 } | |
8750 | |
8751 test_initializer_executable_with_unimported_return_type() { | 8480 test_initializer_executable_with_unimported_return_type() { |
8752 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); | 8481 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); |
8753 addNamedSource('/b.dart', 'class D {}'); | 8482 addNamedSource('/b.dart', 'class D {}'); |
8754 // The synthetic executable for `v` has type `() => D`; `D` is defined in | 8483 // The synthetic executable for `v` has type `() => D`; `D` is defined in |
8755 // a library that is not imported. Note: `v` is mis-typed as `int` to | 8484 // a library that is not imported. Note: `v` is mis-typed as `int` to |
8756 // prevent type propagation, which would complicate the test. | 8485 // prevent type propagation, which would complicate the test. |
8757 UnlinkedVariable variable = serializeVariableText( | 8486 UnlinkedVariable variable = serializeVariableText( |
8758 'import "a.dart"; int v = new C().d;', | 8487 'import "a.dart"; int v = new C().d;', |
8759 allowErrors: true); | 8488 allowErrors: true); |
8760 expect(variable.initializer.returnType, isNull); | 8489 expect(variable.initializer.returnType, isNull); |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9429 className: 'C') | 9158 className: 'C') |
9430 .executables[0]; | 9159 .executables[0]; |
9431 expect(f.inferredReturnTypeSlot, 0); | 9160 expect(f.inferredReturnTypeSlot, 0); |
9432 } | 9161 } |
9433 | 9162 |
9434 test_nested_generic_functions() { | 9163 test_nested_generic_functions() { |
9435 UnlinkedExecutable executable = serializeVariableText(''' | 9164 UnlinkedExecutable executable = serializeVariableText(''' |
9436 var v = (() { | 9165 var v = (() { |
9437 void f<T, U>() { | 9166 void f<T, U>() { |
9438 void g<V, W>() { | 9167 void g<V, W>() { |
9439 void h<X, Y>() { | 9168 void h<X, Y>(T t, U u, V v W w, X x, Y y) { |
9440 T t; | |
9441 U u; | |
9442 V v; | |
9443 W w; | |
9444 X x; | |
9445 Y y; | |
9446 } | 9169 } |
9447 } | 9170 } |
9448 } | 9171 } |
9449 }); | 9172 }); |
9450 ''').initializer.localFunctions[0].localFunctions[0]; | 9173 ''').initializer.localFunctions[0].localFunctions[0]; |
9451 expect(executable.typeParameters, hasLength(2)); | 9174 expect(executable.typeParameters, hasLength(2)); |
9452 expect(executable.localFunctions[0].typeParameters, hasLength(2)); | 9175 expect(executable.localFunctions[0].typeParameters, hasLength(2)); |
9453 expect(executable.localFunctions[0].localFunctions[0].typeParameters, | 9176 expect(executable.localFunctions[0].localFunctions[0].typeParameters, |
9454 hasLength(2)); | 9177 hasLength(2)); |
9455 List<UnlinkedVariable> localVariables = | 9178 List<UnlinkedParam> parameters = |
9456 executable.localFunctions[0].localFunctions[0].localVariables; | 9179 executable.localFunctions[0].localFunctions[0].parameters; |
9457 checkParamTypeRef(findVariable('t', variables: localVariables).type, 6); | 9180 checkParamTypeRef(findParameter(parameters, 't').type, 6); |
9458 checkParamTypeRef(findVariable('u', variables: localVariables).type, 5); | 9181 checkParamTypeRef(findParameter(parameters, 'u').type, 5); |
9459 checkParamTypeRef(findVariable('v', variables: localVariables).type, 4); | 9182 checkParamTypeRef(findParameter(parameters, 'v').type, 4); |
9460 checkParamTypeRef(findVariable('w', variables: localVariables).type, 3); | 9183 checkParamTypeRef(findParameter(parameters, 'w').type, 3); |
9461 checkParamTypeRef(findVariable('x', variables: localVariables).type, 2); | 9184 checkParamTypeRef(findParameter(parameters, 'x').type, 2); |
9462 checkParamTypeRef(findVariable('y', variables: localVariables).type, 1); | 9185 checkParamTypeRef(findParameter(parameters, 'y').type, 1); |
9463 } | 9186 } |
9464 | 9187 |
9465 test_parameter_visibleRange_abstractMethod() { | 9188 test_parameter_visibleRange_abstractMethod() { |
9466 UnlinkedExecutable m = findExecutable('m', | 9189 UnlinkedExecutable m = findExecutable('m', |
9467 executables: | 9190 executables: |
9468 serializeClassText('abstract class C { m(p); }').executables, | 9191 serializeClassText('abstract class C { m(p); }').executables, |
9469 failIfAbsent: true); | 9192 failIfAbsent: true); |
9470 _assertParameterZeroVisibleRange(m.parameters[0]); | 9193 _assertParameterZeroVisibleRange(m.parameters[0]); |
9471 } | 9194 } |
9472 | 9195 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9705 UnlinkedVariable variable = serializeVariableText(''' | 9428 UnlinkedVariable variable = serializeVariableText(''' |
9706 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1; | 9429 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1; |
9707 bool f() => true; | 9430 bool f() => true; |
9708 '''); | 9431 '''); |
9709 EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot); | 9432 EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot); |
9710 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); | 9433 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); |
9711 expect(inferredType.syntheticParams, hasLength(1)); | 9434 expect(inferredType.syntheticParams, hasLength(1)); |
9712 checkLinkedTypeRef(inferredType.syntheticParams[0].type, null, '*bottom*'); | 9435 checkLinkedTypeRef(inferredType.syntheticParams[0].type, null, '*bottom*'); |
9713 } | 9436 } |
9714 | 9437 |
9715 test_syntheticFunctionType_genericClosure_inGenericFunction() { | |
9716 if (skipFullyLinkedData) { | |
9717 return; | |
9718 } | |
9719 if (!strongMode) { | |
9720 // The test below uses generic comment syntax because proper generic | |
9721 // method syntax doesn't support generic closures. So it can only run in | |
9722 // strong mode. | |
9723 // TODO(paulberry): once proper generic method syntax supports generic | |
9724 // closures, rewrite the test below without using generic comment syntax, | |
9725 // and remove this hack. See dartbug.com/25819 | |
9726 return; | |
9727 } | |
9728 UnlinkedVariable variable = serializeExecutableText(''' | |
9729 void f<T, U>(bool b) { | |
9730 final v = b ? /*<V>*/(T t, U u, V v) => 0 : /*<V>*/(T t, U u, V v) => 1; | |
9731 } | |
9732 ''').localVariables[0]; | |
9733 EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot); | |
9734 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); | |
9735 expect(inferredType.syntheticParams, hasLength(3)); | |
9736 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); | |
9737 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); | |
9738 checkLinkedTypeRef(inferredType.syntheticParams[2].type, null, '*bottom*'); | |
9739 } | |
9740 | |
9741 test_syntheticFunctionType_inGenericClass() { | 9438 test_syntheticFunctionType_inGenericClass() { |
9742 if (skipFullyLinkedData) { | 9439 if (skipFullyLinkedData) { |
9743 return; | 9440 return; |
9744 } | 9441 } |
9745 UnlinkedVariable variable = serializeClassText(''' | 9442 UnlinkedVariable variable = serializeClassText(''' |
9746 class C<T, U> { | 9443 class C<T, U> { |
9747 var v = f() ? (T t, U u) => 0 : (T t, U u) => 1; | 9444 var v = f() ? (T t, U u) => 0 : (T t, U u) => 1; |
9748 } | 9445 } |
9749 bool f() => false; | 9446 bool f() => false; |
9750 ''').fields[0]; | 9447 ''').fields[0]; |
9751 EntityRef inferredType = | 9448 EntityRef inferredType = |
9752 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); | 9449 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); |
9753 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); | 9450 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); |
9754 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); | 9451 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); |
9755 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); | 9452 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); |
9756 } | 9453 } |
9757 | 9454 |
9758 test_syntheticFunctionType_inGenericFunction() { | |
9759 if (skipFullyLinkedData) { | |
9760 return; | |
9761 } | |
9762 UnlinkedVariable variable = serializeExecutableText(''' | |
9763 void f<T, U>(bool b) { | |
9764 var v = b ? (T t, U u) => 0 : (T t, U u) => 1; | |
9765 } | |
9766 ''').localVariables[0]; | |
9767 EntityRef inferredType = | |
9768 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); | |
9769 checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int'); | |
9770 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); | |
9771 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); | |
9772 } | |
9773 | |
9774 test_type_arguments_explicit() { | 9455 test_type_arguments_explicit() { |
9775 EntityRef typeRef = serializeTypeText('List<int>'); | 9456 EntityRef typeRef = serializeTypeText('List<int>'); |
9776 checkTypeRef(typeRef, 'dart:core', 'List', | 9457 checkTypeRef(typeRef, 'dart:core', 'List', |
9777 numTypeParameters: 1, numTypeArguments: 1); | 9458 numTypeParameters: 1, numTypeArguments: 1); |
9778 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'int'); | 9459 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'int'); |
9779 } | 9460 } |
9780 | 9461 |
9781 test_type_arguments_explicit_dynamic() { | 9462 test_type_arguments_explicit_dynamic() { |
9782 EntityRef typeRef = serializeTypeText('List<dynamic>'); | 9463 EntityRef typeRef = serializeTypeText('List<dynamic>'); |
9783 checkTypeRef(typeRef, 'dart:core', 'List', | 9464 checkTypeRef(typeRef, 'dart:core', 'List', |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10431 | 10112 |
10432 test_variable_initializer_literal() { | 10113 test_variable_initializer_literal() { |
10433 UnlinkedVariable variable = serializeVariableText('var v = 42;'); | 10114 UnlinkedVariable variable = serializeVariableText('var v = 42;'); |
10434 UnlinkedExecutable initializer = variable.initializer; | 10115 UnlinkedExecutable initializer = variable.initializer; |
10435 expect(initializer, isNotNull); | 10116 expect(initializer, isNotNull); |
10436 if (includeInformative) { | 10117 if (includeInformative) { |
10437 expect(initializer.nameOffset, 8); | 10118 expect(initializer.nameOffset, 8); |
10438 } | 10119 } |
10439 expect(initializer.name, isEmpty); | 10120 expect(initializer.name, isEmpty); |
10440 expect(initializer.localFunctions, isEmpty); | 10121 expect(initializer.localFunctions, isEmpty); |
10441 expect(initializer.localVariables, isEmpty); | |
10442 } | 10122 } |
10443 | 10123 |
10444 test_variable_initializer_noInitializer() { | 10124 test_variable_initializer_noInitializer() { |
10445 UnlinkedVariable variable = serializeVariableText('var v;'); | 10125 UnlinkedVariable variable = serializeVariableText('var v;'); |
10446 expect(variable.initializer, isNull); | 10126 expect(variable.initializer, isNull); |
10447 } | 10127 } |
10448 | 10128 |
10449 test_variable_initializer_withLocals() { | 10129 test_variable_initializer_withLocals() { |
10450 String text = 'var v = <dynamic, dynamic>{"1": () { f1() {} var v1; }, ' | 10130 String text = 'var v = <dynamic, dynamic>{"1": () { f1() {} var v1; }, ' |
10451 '"2": () { f2() {} var v2; }};'; | 10131 '"2": () { f2() {} var v2; }};'; |
(...skipping 11 matching lines...) Expand all Loading... |
10463 if (includeInformative) { | 10143 if (includeInformative) { |
10464 expect(closure.nameOffset, text.indexOf('() { f1()')); | 10144 expect(closure.nameOffset, text.indexOf('() { f1()')); |
10465 } | 10145 } |
10466 expect(closure.name, isEmpty); | 10146 expect(closure.name, isEmpty); |
10467 // closure - f1 | 10147 // closure - f1 |
10468 expect(closure.localFunctions, hasLength(1)); | 10148 expect(closure.localFunctions, hasLength(1)); |
10469 expect(closure.localFunctions[0].name, 'f1'); | 10149 expect(closure.localFunctions[0].name, 'f1'); |
10470 if (includeInformative) { | 10150 if (includeInformative) { |
10471 expect(closure.localFunctions[0].nameOffset, text.indexOf('f1()')); | 10151 expect(closure.localFunctions[0].nameOffset, text.indexOf('f1()')); |
10472 } | 10152 } |
10473 // closure - v1 | |
10474 expect(closure.localVariables, hasLength(1)); | |
10475 expect(closure.localVariables[0].name, 'v1'); | |
10476 if (includeInformative) { | |
10477 expect(closure.localVariables[0].nameOffset, text.indexOf('v1;')); | |
10478 } | |
10479 } | 10153 } |
10480 // closure: () { f2() {} var v2; } | 10154 // closure: () { f2() {} var v2; } |
10481 { | 10155 { |
10482 UnlinkedExecutable closure = initializer.localFunctions[1]; | 10156 UnlinkedExecutable closure = initializer.localFunctions[1]; |
10483 if (includeInformative) { | 10157 if (includeInformative) { |
10484 expect(closure.nameOffset, text.indexOf('() { f2()')); | 10158 expect(closure.nameOffset, text.indexOf('() { f2()')); |
10485 } | 10159 } |
10486 expect(closure.name, isEmpty); | 10160 expect(closure.name, isEmpty); |
10487 // closure - f1 | 10161 // closure - f1 |
10488 expect(closure.localFunctions, hasLength(1)); | 10162 expect(closure.localFunctions, hasLength(1)); |
10489 expect(closure.localFunctions[0].name, 'f2'); | 10163 expect(closure.localFunctions[0].name, 'f2'); |
10490 if (includeInformative) { | 10164 if (includeInformative) { |
10491 expect(closure.localFunctions[0].nameOffset, text.indexOf('f2()')); | 10165 expect(closure.localFunctions[0].nameOffset, text.indexOf('f2()')); |
10492 } | 10166 } |
10493 // closure - v1 | |
10494 expect(closure.localVariables, hasLength(1)); | |
10495 expect(closure.localVariables[0].name, 'v2'); | |
10496 if (includeInformative) { | |
10497 expect(closure.localVariables[0].nameOffset, text.indexOf('v2;')); | |
10498 } | |
10499 } | 10167 } |
10500 } | 10168 } |
10501 | 10169 |
10502 test_variable_name() { | 10170 test_variable_name() { |
10503 UnlinkedVariable variable = | 10171 UnlinkedVariable variable = |
10504 serializeVariableText('int i;', variableName: 'i'); | 10172 serializeVariableText('int i;', variableName: 'i'); |
10505 expect(variable.name, 'i'); | 10173 expect(variable.name, 'i'); |
10506 } | 10174 } |
10507 | 10175 |
10508 test_variable_no_flags() { | 10176 test_variable_no_flags() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10628 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 10296 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
10629 ]); | 10297 ]); |
10630 } | 10298 } |
10631 | 10299 |
10632 void _assertCodeRange(CodeRange codeRange, int offset, int length) { | 10300 void _assertCodeRange(CodeRange codeRange, int offset, int length) { |
10633 expect(codeRange, isNotNull); | 10301 expect(codeRange, isNotNull); |
10634 expect(codeRange.offset, offset); | 10302 expect(codeRange.offset, offset); |
10635 expect(codeRange.length, length); | 10303 expect(codeRange.length, length); |
10636 } | 10304 } |
10637 | 10305 |
10638 void _assertExecutableVisible(String code, UnlinkedExecutable f, | |
10639 String visibleBegin, String visibleEnd) { | |
10640 int expectedVisibleOffset = code.indexOf(visibleBegin); | |
10641 int expectedVisibleLength = | |
10642 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; | |
10643 expect(f.visibleOffset, expectedVisibleOffset); | |
10644 expect(f.visibleLength, expectedVisibleLength); | |
10645 } | |
10646 | |
10647 void _assertParameterVisible( | 10306 void _assertParameterVisible( |
10648 String code, UnlinkedParam p, String visibleBegin, String visibleEnd) { | 10307 String code, UnlinkedParam p, String visibleBegin, String visibleEnd) { |
10649 int expectedVisibleOffset = code.indexOf(visibleBegin); | 10308 int expectedVisibleOffset = code.indexOf(visibleBegin); |
10650 int expectedVisibleLength = | 10309 int expectedVisibleLength = |
10651 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; | 10310 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; |
10652 expect(p.visibleOffset, expectedVisibleOffset); | 10311 expect(p.visibleOffset, expectedVisibleOffset); |
10653 expect(p.visibleLength, expectedVisibleLength); | 10312 expect(p.visibleLength, expectedVisibleLength); |
10654 } | 10313 } |
10655 | 10314 |
10656 void _assertParameterZeroVisibleRange(UnlinkedParam p) { | 10315 void _assertParameterZeroVisibleRange(UnlinkedParam p) { |
(...skipping 26 matching lines...) Expand all Loading... |
10683 ], | 10342 ], |
10684 ints: [ | 10343 ints: [ |
10685 2 | 10344 2 |
10686 ], | 10345 ], |
10687 strings: [], | 10346 strings: [], |
10688 referenceValidators: [ | 10347 referenceValidators: [ |
10689 (EntityRef r) => checkTypeRef(r, null, 'a', | 10348 (EntityRef r) => checkTypeRef(r, null, 'a', |
10690 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 10349 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
10691 ]); | 10350 ]); |
10692 } | 10351 } |
10693 | |
10694 void _assertVariableVisible( | |
10695 String code, UnlinkedVariable v, String visibleBegin, String visibleEnd) { | |
10696 int expectedVisibleOffset = code.indexOf(visibleBegin); | |
10697 int expectedVisibleLength = | |
10698 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; | |
10699 expect(v.visibleOffset, expectedVisibleOffset); | |
10700 expect(v.visibleLength, expectedVisibleLength); | |
10701 } | |
10702 } | 10352 } |
10703 | 10353 |
10704 /** | 10354 /** |
10705 * Description of expectations for a prelinked prefix reference. | 10355 * Description of expectations for a prelinked prefix reference. |
10706 */ | 10356 */ |
10707 class _PrefixExpectation { | 10357 class _PrefixExpectation { |
10708 final ReferenceKind kind; | 10358 final ReferenceKind kind; |
10709 final String name; | 10359 final String name; |
10710 final String absoluteUri; | 10360 final String absoluteUri; |
10711 final int numTypeParameters; | 10361 final int numTypeParameters; |
10712 | 10362 |
10713 _PrefixExpectation(this.kind, this.name, | 10363 _PrefixExpectation(this.kind, this.name, |
10714 {this.absoluteUri, this.numTypeParameters: 0}); | 10364 {this.absoluteUri, this.numTypeParameters: 0}); |
10715 } | 10365 } |
OLD | NEW |