Chromium Code Reviews| Index: pkg/analyzer/test/src/summary/summary_common.dart |
| diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart |
| index de38e8ee03851d0610d7a955ba24df2de5e23bb6..8df7ff9da5810e5c2fd85b4c826cb610e5b71174 100644 |
| --- a/pkg/analyzer/test/src/summary/summary_common.dart |
| +++ b/pkg/analyzer/test/src/summary/summary_common.dart |
| @@ -314,9 +314,9 @@ abstract class SummaryTest { |
| } |
| /** |
| - * Test an inferred type. If strong mode is disabled, verify that the given |
| - * [slotId] exists and has no associated type. Otherwise, behave as in |
| - * [checkLinkedTypeSlot]. |
| + * Test an inferred type. If [onlyInStrongMode] is `true` (the default) and |
| + * strong mode is disabled, verify that the given [slotId] exists and has no |
| + * associated type. Otherwise, behave as in [checkLinkedTypeSlot]. |
| */ |
| void checkInferredTypeSlot( |
| int slotId, String absoluteUri, String relativeUri, String expectedName, |
| @@ -325,8 +325,9 @@ abstract class SummaryTest { |
| int expectedTargetUnit: 0, |
| LinkedUnit linkedSourceUnit, |
| UnlinkedUnit unlinkedSourceUnit, |
| - int numTypeParameters: 0}) { |
| - if (strongMode) { |
| + int numTypeParameters: 0, |
| + bool onlyInStrongMode: true}) { |
| + if (strongMode || !onlyInStrongMode) { |
| checkLinkedTypeSlot(slotId, absoluteUri, relativeUri, expectedName, |
| allowTypeArguments: allowTypeParameters, |
| expectedKind: expectedKind, |
| @@ -1317,6 +1318,59 @@ class E {} |
| expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); |
| } |
| + test_closure_executable_with_bottom_return_type() { |
| + UnlinkedExecutable executable = |
| + serializeExecutableText('f() { print((() => null)()); }'); |
| + expect(executable.localFunctions, hasLength(1)); |
| + expect(executable.localFunctions[0].returnType, isNull); |
| + if (strongMode) { |
| + // Strong mode infers a type for the closure of `() => dynamic`, so the |
| + // inferred return type slot should be empty. |
| + expect( |
| + getTypeRefForSlot( |
| + executable.localFunctions[0].inferredReturnTypeSlot), |
| + isNull); |
| + } else { |
| + // Strong mode infers a type for the closure of `() => dynamic`, so the |
| + // 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.
|
| + // Spec mode infers a type for the closure of `() => Bottom`. |
| + checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, |
| + null, null, '*bottom*', |
| + onlyInStrongMode: false); |
| + } |
| + } |
| + |
| + test_closure_executable_with_imported_return_type() { |
| + addNamedSource('/a.dart', 'class C { D d; } class D {}'); |
| + // The closure has type `() => D`; `D` is defined in a library that is |
| + // imported. |
| + UnlinkedExecutable executable = serializeExecutableText( |
| + 'import "a.dart"; f() { print((() => new C().d)()); }'); |
| + expect(executable.localFunctions, hasLength(1)); |
| + expect(executable.localFunctions[0].returnType, isNull); |
| + checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, |
| + absUri('/a.dart'), 'a.dart', 'D', |
| + onlyInStrongMode: false); |
| + checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); |
| + } |
| + |
| + test_closure_executable_with_unimported_return_type() { |
| + addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); |
| + addNamedSource('/b.dart', 'class D {}'); |
| + // The closure has type `() => D`; `D` is defined in a library that is not |
| + // imported. |
| + UnlinkedExecutable executable = serializeExecutableText( |
| + 'import "a.dart"; f() { print((() => new C().d)()); }'); |
| + expect(executable.localFunctions, hasLength(1)); |
| + expect(executable.localFunctions[0].returnType, isNull); |
| + checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, |
| + absUri('/b.dart'), 'b.dart', 'D', |
| + onlyInStrongMode: false); |
| + if (!skipFullyLinkedData) { |
| + checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); |
| + } |
| + } |
| + |
| test_constExpr_binary_add() { |
| UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;'); |
| _assertUnlinkedConst(variable.constExpr, operators: [ |
| @@ -5474,6 +5528,48 @@ p.B b; |
| checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); |
| } |
| + test_initializer_executable_with_bottom_return_type() { |
| + // The synthetic executable for `v` has type `() => Bottom`. |
| + UnlinkedVariable variable = serializeVariableText('int v = null;'); |
| + expect(variable.initializer.returnType, isNull); |
| + checkInferredTypeSlot( |
| + variable.initializer.inferredReturnTypeSlot, null, null, '*bottom*', |
| + onlyInStrongMode: false); |
| + } |
| + |
| + test_initializer_executable_with_imported_return_type() { |
| + addNamedSource('/a.dart', 'class C { D d; } class D {}'); |
| + // The synthetic executable for `v` has type `() => D`; `D` is defined in |
| + // a library that is imported. Note: `v` is mis-typed as `int` to prevent |
| + // type propagation, which would complicate the test. |
| + UnlinkedVariable variable = serializeVariableText( |
| + 'import "a.dart"; int v = new C().d;', |
| + allowErrors: true); |
| + expect(variable.initializer.returnType, isNull); |
| + checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, |
| + absUri('/a.dart'), 'a.dart', 'D', |
| + onlyInStrongMode: false); |
| + checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); |
| + } |
| + |
| + test_initializer_executable_with_unimported_return_type() { |
| + addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); |
| + addNamedSource('/b.dart', 'class D {}'); |
| + // The synthetic executable for `v` has type `() => D`; `D` is defined in |
| + // a library that is not imported. Note: `v` is mis-typed as `int` to |
| + // prevent type propagation, which would complicate the test. |
| + UnlinkedVariable variable = serializeVariableText( |
| + 'import "a.dart"; int v = new C().d;', |
| + allowErrors: true); |
| + expect(variable.initializer.returnType, isNull); |
| + checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, |
| + absUri('/b.dart'), 'b.dart', 'D', |
| + onlyInStrongMode: false); |
| + if (!skipFullyLinkedData) { |
| + checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); |
| + } |
| + } |
| + |
| test_invalid_prefix_dynamic() { |
| if (checkAstDerivedData) { |
| // TODO(paulberry): get this to work properly. |