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 adb595b47bcbf503deec693bf169580dc2214235..a2e2fe5fae9f203e19f44ba228b09f0c7bf79a6a 100644 |
| --- a/pkg/analyzer/test/src/summary/summary_common.dart |
| +++ b/pkg/analyzer/test/src/summary/summary_common.dart |
| @@ -375,16 +375,12 @@ abstract class SummaryTest { |
| if (!allowTypeParameters) { |
| expect(typeRef.typeArguments, isEmpty); |
| } |
| - checkTypeRefCommonElements( |
| - index, |
| - absoluteUri, |
| - relativeUri, |
| - expectedName, |
| - expectedKind, |
| - expectedTargetUnit, |
| - linkedSourceUnit, |
| - unlinkedSourceUnit, |
| - numTypeParameters); |
| + checkReferenceIndex(index, absoluteUri, relativeUri, expectedName, |
| + expectedKind: expectedKind, |
| + expectedTargetUnit: expectedTargetUnit, |
| + linkedSourceUnit: linkedSourceUnit, |
| + unlinkedSourceUnit: unlinkedSourceUnit, |
| + numTypeParameters: numTypeParameters); |
| } |
| /** |
| @@ -452,6 +448,66 @@ abstract class SummaryTest { |
| } |
| /** |
| + * Check the data structures that are reachable from an index in the |
| + * references table.. If the reference in question is an explicit |
| + * reference, return the [UnlinkedReference] that is used to make the |
| + * explicit reference. If the type reference in question is an implicit |
| + * reference, return `null`. |
| + */ |
| + UnlinkedReference checkReferenceIndex(int referenceIndex, String absoluteUri, |
| + String relativeUri, String expectedName, |
| + {ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| + int expectedTargetUnit: 0, |
| + LinkedUnit linkedSourceUnit, |
| + UnlinkedUnit unlinkedSourceUnit, |
| + int numTypeParameters: 0}) { |
| + linkedSourceUnit ??= definingUnit; |
| + unlinkedSourceUnit ??= unlinkedUnits[0]; |
| + LinkedReference referenceResolution = |
| + linkedSourceUnit.references[referenceIndex]; |
| + String name; |
| + UnlinkedReference reference; |
| + if (referenceIndex < unlinkedSourceUnit.references.length) { |
| + // This is an explicit reference, so its name and prefix should be in |
| + // [UnlinkedUnit.references]. |
| + expect(referenceResolution.name, isEmpty); |
| + reference = unlinkedSourceUnit.references[referenceIndex]; |
| + name = reference.name; |
| + if (reference.prefixReference != 0) { |
| + // Prefixes should appear in the references table before any reference |
| + // that uses them. |
| + expect(reference.prefixReference, lessThan(referenceIndex)); |
| + } |
| + } else { |
| + // This is an implicit reference, so its name should be in |
| + // [LinkedUnit.references]. |
| + name = referenceResolution.name; |
| + } |
| + // Index 0 is reserved. |
| + expect(referenceIndex, isNot(0)); |
| + if (absoluteUri == null) { |
| + expect(referenceResolution.dependency, 0); |
| + } else { |
| + checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); |
| + } |
| + if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) { |
| + // summarize_elements.dart isn't yet able to record the name of |
| + // unresolved references. TODO(paulberry): fix this. |
| + expect(name, '*unresolved*'); |
| + } else { |
| + if (expectedName == null) { |
| + expect(name, isEmpty); |
| + } else { |
| + expect(name, expectedName); |
| + } |
| + } |
| + expect(referenceResolution.kind, expectedKind); |
| + expect(referenceResolution.unit, expectedTargetUnit); |
| + expect(referenceResolution.numTypeParameters, numTypeParameters); |
| + return reference; |
| + } |
| + |
| + /** |
| * Verify that the given [typeRef] represents a reference to a type declared |
| * in a file reachable via [absoluteUri] and [relativeUri], having name |
| * [expectedName]. If [expectedPrefix] is supplied, verify that the type is |
| @@ -482,16 +538,13 @@ abstract class SummaryTest { |
| if (!allowTypeParameters) { |
| expect(typeRef.typeArguments, isEmpty); |
| } |
| - UnlinkedReference reference = checkTypeRefCommonElements( |
| - index, |
| - absoluteUri, |
| - relativeUri, |
| - expectedName, |
| - expectedKind, |
| - expectedTargetUnit, |
| - linkedSourceUnit, |
| - unlinkedSourceUnit, |
| - numTypeParameters); |
| + UnlinkedReference reference = checkReferenceIndex( |
| + index, absoluteUri, relativeUri, expectedName, |
| + expectedKind: expectedKind, |
| + expectedTargetUnit: expectedTargetUnit, |
| + linkedSourceUnit: linkedSourceUnit, |
| + unlinkedSourceUnit: unlinkedSourceUnit, |
| + numTypeParameters: numTypeParameters); |
| expect(reference, isNotNull, |
| reason: 'Unlinked type refs must refer to an explicit reference'); |
| if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) { |
| @@ -503,7 +556,7 @@ abstract class SummaryTest { |
| } else if (prefixExpectations != null) { |
| for (_PrefixExpectation expectation in prefixExpectations) { |
| expect(reference.prefixReference, isNot(0)); |
| - reference = checkTypeRefCommonElements( |
| + reference = checkReferenceIndex( |
| reference.prefixReference, |
| expectation.inLibraryDefiningUnit |
| ? null |
| @@ -512,11 +565,11 @@ abstract class SummaryTest { |
| ? null |
| : expectation.relativeUri ?? relativeUri, |
| expectation.name, |
| - expectation.kind, |
| - expectedTargetUnit, |
| - linkedSourceUnit, |
| - unlinkedSourceUnit, |
| - expectation.numTypeParameters); |
| + expectedKind: expectation.kind, |
| + expectedTargetUnit: expectedTargetUnit, |
| + linkedSourceUnit: linkedSourceUnit, |
| + unlinkedSourceUnit: unlinkedSourceUnit, |
| + numTypeParameters: expectation.numTypeParameters); |
| } |
| expect(reference.prefixReference, 0); |
| } else { |
| @@ -525,68 +578,6 @@ abstract class SummaryTest { |
| } |
| /** |
| - * Check the data structures that are common between [checkTypeRef] and |
| - * [checkLinkedTypeRef]. If the type reference in question is an explicit |
| - * reference, return the [UnlinkedReference] that is used to make the |
| - * explicit reference. If the type reference in question is an implicit |
| - * reference, return `null`. |
| - */ |
| - UnlinkedReference checkTypeRefCommonElements( |
| - int referenceIndex, |
| - String absoluteUri, |
| - String relativeUri, |
| - String expectedName, |
| - ReferenceKind expectedKind, |
| - int expectedTargetUnit, |
| - LinkedUnit linkedSourceUnit, |
| - UnlinkedUnit unlinkedSourceUnit, |
| - int numTypeParameters) { |
| - unlinkedSourceUnit ??= unlinkedUnits[0]; |
| - LinkedReference referenceResolution = |
| - linkedSourceUnit.references[referenceIndex]; |
| - String name; |
| - UnlinkedReference reference; |
| - if (referenceIndex < unlinkedSourceUnit.references.length) { |
| - // This is an explicit reference, so its name and prefix should be in |
| - // [UnlinkedUnit.references]. |
| - expect(referenceResolution.name, isEmpty); |
| - reference = unlinkedSourceUnit.references[referenceIndex]; |
| - name = reference.name; |
| - if (reference.prefixReference != 0) { |
| - // Prefixes should appear in the references table before any reference |
| - // that uses them. |
| - expect(reference.prefixReference, lessThan(referenceIndex)); |
| - } |
| - } else { |
| - // This is an implicit reference, so its name should be in |
| - // [LinkedUnit.references]. |
| - name = referenceResolution.name; |
| - } |
| - // Index 0 is reserved. |
| - expect(referenceIndex, isNot(0)); |
| - if (absoluteUri == null) { |
| - expect(referenceResolution.dependency, 0); |
| - } else { |
| - checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); |
| - } |
| - if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) { |
| - // summarize_elements.dart isn't yet able to record the name of |
| - // unresolved references. TODO(paulberry): fix this. |
| - expect(name, '*unresolved*'); |
| - } else { |
| - if (expectedName == null) { |
| - expect(name, isEmpty); |
| - } else { |
| - expect(name, expectedName); |
| - } |
| - } |
| - expect(referenceResolution.kind, expectedKind); |
| - expect(referenceResolution.unit, expectedTargetUnit); |
| - expect(referenceResolution.numTypeParameters, numTypeParameters); |
| - return reference; |
| - } |
| - |
| - /** |
| * Verify that the given [typeRef] represents a reference to an unresolved |
| * type. |
| */ |
| @@ -4001,6 +3992,66 @@ p.B b; |
| checkLinkedTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int'); |
| } |
| + test_inferred_type_refers_to_method_function_typed_parameter_type() { |
| + if (!strongMode || skipFullyLinkedData) { |
| + return; |
| + } |
| + UnlinkedClass cls = serializeClassText( |
| + 'class C extends D { void f(int x, g) {} }' |
| + ' abstract class D { void f(int x, int g(String s)); }', |
| + className: 'C'); |
| + EntityRef type = |
| + getTypeRefForSlot(cls.executables[0].parameters[1].inferredTypeSlot); |
| + // Check that parameter g's inferred type is the type implied by D.f's 1st |
| + // (zero-based) parameter. |
| + expect(type.implicitFunctionTypeIndices, hasLength(1)); |
| + expect(type.implicitFunctionTypeIndices[0], 1); |
|
scheglov
2016/01/29 20:56:56
I think just equality would work fine and replace
Paul Berry
2016/01/29 21:13:18
Whoops, I accidentally just landed the CL without
|
| + expect(type.paramReference, 0); |
| + expect(type.typeArguments, isEmpty); |
| + expect(type.reference, |
| + greaterThanOrEqualTo(unlinkedUnits[0].references.length)); |
| + LinkedReference linkedReference = |
| + linked.units[0].references[type.reference]; |
| + expect(linkedReference.dependency, 0); |
| + expect(linkedReference.kind, ReferenceKind.method); |
| + expect(linkedReference.name, 'f'); |
| + expect(linkedReference.numTypeParameters, 0); |
| + expect(linkedReference.unit, 0); |
| + expect(linkedReference.containingReference, isNot(0)); |
| + expect(linkedReference.containingReference, lessThan(type.reference)); |
| + checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); |
| + } |
| + |
| + test_inferred_type_refers_to_setter_function_typed_parameter_type() { |
| + if (!strongMode || skipFullyLinkedData) { |
| + return; |
| + } |
| + UnlinkedClass cls = serializeClassText( |
| + 'class C extends D { void set f(g) {} }' |
| + ' abstract class D { void set f(int g(String s)); }', |
| + className: 'C'); |
| + EntityRef type = |
| + getTypeRefForSlot(cls.executables[0].parameters[0].inferredTypeSlot); |
| + // Check that parameter g's inferred type is the type implied by D.f's 1st |
| + // (zero-based) parameter. |
| + expect(type.implicitFunctionTypeIndices, hasLength(1)); |
| + expect(type.implicitFunctionTypeIndices[0], 0); |
| + expect(type.paramReference, 0); |
| + expect(type.typeArguments, isEmpty); |
| + expect(type.reference, |
| + greaterThanOrEqualTo(unlinkedUnits[0].references.length)); |
| + LinkedReference linkedReference = |
| + linked.units[0].references[type.reference]; |
| + expect(linkedReference.dependency, 0); |
| + expect(linkedReference.kind, ReferenceKind.propertyAccessor); |
| + expect(linkedReference.name, 'f='); |
| + expect(linkedReference.numTypeParameters, 0); |
| + expect(linkedReference.unit, 0); |
| + expect(linkedReference.containingReference, isNot(0)); |
| + expect(linkedReference.containingReference, lessThan(type.reference)); |
| + checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); |
| + } |
| + |
| test_invalid_prefix_dynamic() { |
| if (checkAstDerivedData) { |
| // TODO(paulberry): get this to work properly. |