Class InferenceTck


public abstract class InferenceTck extends AbstractByteCodeWriterTck
Inference of method type arguments: wildcard capture and containment, bound checks, least upper bounds, generic variable arity calls and the requested return type. Each generated call must behave as javac's call on a compiled fixture.

A backend runs these tests by extending this class and implementing AbstractByteCodeWriterTck.write(io.micronaut.sourcegen.model.ObjectDef).

Since:
2.3
  • Constructor Details

    • InferenceTck

      public InferenceTck()
  • Method Details

    • genericArrayCallsPreserveValuesAcrossRanks

      @ParameterizedTest(name="an array of rank {0} keeps its identity through a bounded generic call") @ValueSource(ints={1,2,3}) public void genericArrayCallsPreserveValuesAcrossRanks(int rank) throws Exception
      A bounded generic call returns the very array it is given, whatever the rank of the array.
      Parameters:
      rank - The rank of the array
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • chainedBoundsKeepTheirRuntimeIdentity

      @ParameterizedTest(name="a chain of {0} dependent bounds returns the value it is given") @ValueSource(ints={1,2,8,9}) public void chainedBoundsKeepTheirRuntimeIdentity(int length) throws Exception
      A call through a chain of type variables, each bounded by the next, returns the value it is given.
      Parameters:
      length - The number of variables in the chain
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • genericArrayCallsPreserveIntersectionBoundValues

      @Test public void genericArrayCallsPreserveIntersectionBoundValues() throws Exception
      Verifies an erased invocation preserves arrays whose elements have intersection bounds.
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • intersectionArraysPreserveCallerTypeArguments

      @Test public void intersectionArraysPreserveCallerTypeArguments() throws Exception
      Verifies array invocation preserves the caller's generic arguments across scopes.
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • nullableIntersectionArraysPreserveNull

      @Test public void nullableIntersectionArraysPreserveNull() throws Exception
      Verifies null remains a valid value for a nullable array with intersection-bounded elements.
      Throws:
      Exception - If the generated program cannot be loaded or invoked
      Since:
      2.3
    • genericVarargsInferTheRuntimeComponentType

      @Test public void genericVarargsInferTheRuntimeComponentType() throws Exception
      Throws:
      Exception
    • upperWildcardConstrainsApplicability

      @Test public void upperWildcardConstrainsApplicability() throws Exception
      Throws:
      Exception
    • lowerWildcardConstrainsApplicability

      @Test public void lowerWildcardConstrainsApplicability() throws Exception
      Throws:
      Exception
    • recursiveBoundConstrainsItsTypeArgument

      @Test public void recursiveBoundConstrainsItsTypeArgument() throws Exception
      Throws:
      Exception
    • repeatedMethodVariableUnifiesAcrossArguments

      @Test public void repeatedMethodVariableUnifiesAcrossArguments() throws Exception
      Throws:
      Exception
    • dependentMethodBoundIsResolvedBeforeApplicability

      @Test public void dependentMethodBoundIsResolvedBeforeApplicability() throws Exception
      Throws:
      Exception
    • genericVarargsKeepNullElementInference

      @Test public void genericVarargsKeepNullElementInference() throws Exception
      Throws:
      Exception
    • genericVarargsComputeCommonSuperclass

      @Test public void genericVarargsComputeCommonSuperclass() throws Exception
      Throws:
      Exception
    • genericVarargsInferenceIncludesFixedParameters

      @Test public void genericVarargsInferenceIncludesFixedParameters() throws Exception
      Throws:
      Exception
    • primitiveArrayIsPackedAsOneSerializableVararg

      @Test public void primitiveArrayIsPackedAsOneSerializableVararg() throws Exception
      Throws:
      Exception
    • constructorWildcardConstrainsApplicability

      @Test public void constructorWildcardConstrainsApplicability() throws Exception
      Throws:
      Exception
    • multiDimensionalGenericVarargsInferComponentRank

      @Test public void multiDimensionalGenericVarargsInferComponentRank() throws Exception
      Throws:
      Exception
    • admissibleWildcardsStillSelectTheSpecificOverload

      @Test public void admissibleWildcardsStillSelectTheSpecificOverload() throws Exception
      Throws:
      Exception
    • capturedUpperWildcardDoesNotAcceptAnArbitrarySubtypeOfItsBound

      @Test public void capturedUpperWildcardDoesNotAcceptAnArbitrarySubtypeOfItsBound() throws Exception
      Throws:
      Exception
    • independentWildcardCapturesCannotBeEquated

      @Test public void independentWildcardCapturesCannotBeEquated() throws Exception
      Throws:
      Exception
    • wildcardUpperAndLowerConstraintsMustAgree

      @Test public void wildcardUpperAndLowerConstraintsMustAgree() throws Exception
      Throws:
      Exception
    • compatibleWildcardTransferStillSelectsGenericOverload

      @Test public void compatibleWildcardTransferStillSelectsGenericOverload() throws Exception
      Throws:
      Exception
    • lowerWildcardCaptureAcceptsValuesWithinItsLowerBound

      @Test public void lowerWildcardCaptureAcceptsValuesWithinItsLowerBound() throws Exception
      Throws:
      Exception
    • wildcardReceiverDoesNotAcceptValuesOfItsUpperBound

      @Test public void wildcardReceiverDoesNotAcceptValuesOfItsUpperBound() throws Exception
      Throws:
      Exception
    • recursiveBoundsMustHoldForOneSharedInferenceSolution

      @Test public void recursiveBoundsMustHoldForOneSharedInferenceSolution() throws Exception
      Throws:
      Exception
    • compatibleRecursiveBoundsStillSelectGenericOverload

      @Test public void compatibleRecursiveBoundsStillSelectGenericOverload() throws Exception
      Throws:
      Exception
    • nestedLowerWildcardConstrainsItsTypeArgument

      @Test public void nestedLowerWildcardConstrainsItsTypeArgument() throws Exception
      Throws:
      Exception
    • compatibleNestedLowerWildcardStillSelectsGenericOverload

      @Test public void compatibleNestedLowerWildcardStillSelectsGenericOverload() throws Exception
      Throws:
      Exception
    • genericVarargsRespectAllBoundsWhenChoosingTheArrayComponent

      @Test public void genericVarargsRespectAllBoundsWhenChoosingTheArrayComponent() throws Exception
      Throws:
      Exception
    • genericArrayInferencePreservesDifferentRanks

      @Test public void genericArrayInferencePreservesDifferentRanks() throws Exception
      Throws:
      Exception
    • methodBoundToAnotherVariableRetainsItsParameterErasure

      @Test public void methodBoundToAnotherVariableRetainsItsParameterErasure() throws Exception
      Throws:
      Exception
    • genericConstructorUsesTheSameCaptureRulesAsMethods

      @Test public void genericConstructorUsesTheSameCaptureRulesAsMethods() throws Exception
      Throws:
      Exception
    • parameterizedReceiverSpecializesTheRequestedReturnType

      @Test public void parameterizedReceiverSpecializesTheRequestedReturnType() throws Exception
      Throws:
      Exception
    • genericMethodSpecializesTheRequestedReturnType

      @Test public void genericMethodSpecializesTheRequestedReturnType() throws Exception
      Throws:
      Exception
    • classAndMethodVariablesSpecializeTheRequestedReturnType

      @Test public void classAndMethodVariablesSpecializeTheRequestedReturnType() throws Exception
      Throws:
      Exception
    • targetTypeSelectsAGenericMethodWithNoArguments

      @Test public void targetTypeSelectsAGenericMethodWithNoArguments() throws Exception
      Throws:
      Exception
    • explicitInstanceMethodReturningTheSpecializedTypeInvokesTheDeclaration

      @Test public void explicitInstanceMethodReturningTheSpecializedTypeInvokesTheDeclaration() throws Exception
      Throws:
      Exception
    • explicitStaticMethodReturningTheTargetTypeInvokesTheDeclaration

      @Test public void explicitStaticMethodReturningTheTargetTypeInvokesTheDeclaration() throws Exception
      Throws:
      Exception
    • nestedWildcardInferencePropagatesTheCapturedUpperBound

      @Test public void nestedWildcardInferencePropagatesTheCapturedUpperBound() throws Exception
      Throws:
      Exception
    • upperOnlyInferenceConstraintsMustSatisfyTheDeclaredBound

      @Test public void upperOnlyInferenceConstraintsMustSatisfyTheDeclaredBound() throws Exception
      Throws:
      Exception
    • incompatibleUpperOnlyInferenceConstraintsExcludeAnOverload

      @Test public void incompatibleUpperOnlyInferenceConstraintsExcludeAnOverload() throws Exception
      Throws:
      Exception
    • nestedGenericArraysInferTheRemainingDimensions

      @Test public void nestedGenericArraysInferTheRemainingDimensions() throws Exception
      Throws:
      Exception
    • emptyVarargsUseTheMethodBoundSpecializedByTheReceiver

      @Test public void emptyVarargsUseTheMethodBoundSpecializedByTheReceiver() throws Exception
      Throws:
      Exception
    • nonemptyVarargsUseTheMethodBoundSpecializedByTheReceiver

      @Test public void nonemptyVarargsUseTheMethodBoundSpecializedByTheReceiver() throws Exception
      Throws:
      Exception
    • lowerWildcardContributesAnUpperInferenceConstraint

      @Test public void lowerWildcardContributesAnUpperInferenceConstraint() throws Exception
      Throws:
      Exception
    • compatibleLowerWildcardStillSelectsGenericOverload

      @Test public void compatibleLowerWildcardStillSelectsGenericOverload() throws Exception
      Throws:
      Exception
    • nestedWildcardPropagatesItsTypeArgumentConstraint

      @Test public void nestedWildcardPropagatesItsTypeArgumentConstraint() throws Exception
      Throws:
      Exception
    • invariantGenericArrayArgumentsConstrainInference

      @Test public void invariantGenericArrayArgumentsConstrainInference() throws Exception
      Throws:
      Exception
    • wildcardArgumentIsContainedByAnotherUpperWildcard

      @Test public void wildcardArgumentIsContainedByAnotherUpperWildcard() throws Exception
      Throws:
      Exception
    • wildcardArgumentIsContainedByAnotherLowerWildcard

      @Test public void wildcardArgumentIsContainedByAnotherLowerWildcard() throws Exception
      Throws:
      Exception
    • wildcardArgumentExcludesAnUnrelatedUpperBound

      @Test public void wildcardArgumentExcludesAnUnrelatedUpperBound() throws Exception
      Throws:
      Exception
    • dependentVariableBoundsPropagateLowerConstraints

      @Test public void dependentVariableBoundsPropagateLowerConstraints() throws Exception
      Throws:
      Exception
    • inferenceFindsACommonInterfaceOfUnrelatedClasses

      @Test public void inferenceFindsACommonInterfaceOfUnrelatedClasses() throws Exception
      Throws:
      Exception
    • boundedVarargsInferACommonInterfaceArray

      @Test public void boundedVarargsInferACommonInterfaceArray() throws Exception
      Throws:
      Exception
    • unboundedVarargsInferACommonInterfaceArray

      @Test public void unboundedVarargsInferACommonInterfaceArray() throws Exception
      Throws:
      Exception
    • varargsInferencePreservesArrayLeastUpperBound

      @Test public void varargsInferencePreservesArrayLeastUpperBound() throws Exception
      Throws:
      Exception
    • genericVarargsUseParameterizedReceiverComponent

      @Test public void genericVarargsUseParameterizedReceiverComponent() throws Exception
      Throws:
      Exception
    • emptyGenericVarargsUseParameterizedReceiverComponent

      @Test public void emptyGenericVarargsUseParameterizedReceiverComponent() throws Exception
      Throws:
      Exception
    • inheritedGenericVarargsUseSpecializedReceiverComponent

      @Test public void inheritedGenericVarargsUseSpecializedReceiverComponent() throws Exception
      Throws:
      Exception
    • genericVarargsWithOneArrayUsesFixedArity

      @Test public void genericVarargsWithOneArrayUsesFixedArity() throws Exception
      Throws:
      Exception
    • unboundedWildcardRemainsApplicable

      @Test public void unboundedWildcardRemainsApplicable() throws Exception
      Throws:
      Exception
    • invariantGenericArrayArgumentCanInferItsComponent

      @Test public void invariantGenericArrayArgumentCanInferItsComponent() throws Exception
      Throws:
      Exception
    • wildcardCaptureRespectsMethodVariableBounds

      @Test public void wildcardCaptureRespectsMethodVariableBounds() throws Exception
      Throws:
      Exception
    • genericArrayTypeArgumentsRemainInvariant

      @Test public void genericArrayTypeArgumentsRemainInvariant() throws Exception
      Throws:
      Exception
    • primitiveMultidimensionalArraysRetainTheirLeastUpperBoundRank

      @Test public void primitiveMultidimensionalArraysRetainTheirLeastUpperBoundRank() throws Exception
      Throws:
      Exception
    • lowerWildcardCaptureAllowsBoxing

      @Test public void lowerWildcardCaptureAllowsBoxing() throws Exception
      Throws:
      Exception
    • lexicalVarargsKeepTheInferredArrayType

      @ParameterizedTest(name="an argument of a method variable written {0} packs the inferred array") @ValueSource(strings={"named","inline"}) public void lexicalVarargsKeepTheInferredArrayType(String declaration) throws Exception
      A variable arity call whose argument is typed by a method type variable, named or declared inline, packs the array javac infers for it.
      Parameters:
      declaration - How the argument's type variable is written: by name or inline with its bound
      Throws:
      Exception - If the generated program cannot be loaded or invoked
    • lowerWildcardStillContributesItsObjectUpperBound

      @Test public void lowerWildcardStillContributesItsObjectUpperBound() throws Exception
      Throws:
      Exception
    • upperWildcardWithNumericBoundRemainsApplicable

      @Test public void upperWildcardWithNumericBoundRemainsApplicable() throws Exception
      Throws:
      Exception
    • upperOnlyConstraintsRejectIncompatibleGenericBounds

      @Test public void upperOnlyConstraintsRejectIncompatibleGenericBounds() throws Exception
      Throws:
      Exception
    • upperOnlyConstraintsAcceptCompatibleGenericBounds

      @Test public void upperOnlyConstraintsAcceptCompatibleGenericBounds() throws Exception
      Throws:
      Exception
    • upperOnlyConstraintsRejectConflictingInterfaceArguments

      @Test public void upperOnlyConstraintsRejectConflictingInterfaceArguments() throws Exception
      Throws:
      Exception
    • nestedGenericEqualityChecksRawTypes

      @Test public void nestedGenericEqualityChecksRawTypes() throws Exception
      Throws:
      Exception
    • methodInferenceUsesTheCallerVariablesBounds

      @Test public void methodInferenceUsesTheCallerVariablesBounds() throws Exception
      Throws:
      Exception
    • wildcardArgumentUsesTheCallerVariablesBounds

      @Test public void wildcardArgumentUsesTheCallerVariablesBounds() throws Exception
      Throws:
      Exception
    • genericInferenceAcceptsRecursiveWildcardBound

      @Test public void genericInferenceAcceptsRecursiveWildcardBound() throws Exception
      Throws:
      Exception
    • genericInferenceRejectsRecursiveWildcardBound

      @Test public void genericInferenceRejectsRecursiveWildcardBound() throws Exception
      Throws:
      Exception
    • leastUpperBoundOfIntegerAndStringIsSerializable

      @Test public void leastUpperBoundOfIntegerAndStringIsSerializable() throws Exception
      Throws:
      Exception
    • leastUpperBoundOrdersInterfacesByName

      @Test public void leastUpperBoundOrdersInterfacesByName() throws Exception
      Throws:
      Exception
    • leastUpperBoundOrdersInterfacesByRank

      @Test public void leastUpperBoundOrdersInterfacesByRank() throws Exception
      Throws:
      Exception
    • arrayArgumentsInferAnArrayComponent

      @Test public void arrayArgumentsInferAnArrayComponent() throws Exception
      Throws:
      Exception
    • primitiveArrayArgumentIsOneElement

      @Test public void primitiveArrayArgumentIsOneElement() throws Exception
      Throws:
      Exception
    • collectionsMaxErasesToObjectAndIsTypedAsRequested

      @Test public void collectionsMaxErasesToObjectAndIsTypedAsRequested() throws Exception
      Throws:
      Exception
    • collectionsMaxOfARecursiveBoundThroughASuperinterface

      @Test public void collectionsMaxOfARecursiveBoundThroughASuperinterface() throws Exception
      Throws:
      Exception
    • enumSetOfPacksTheVariableArityTail

      @Test public void enumSetOfPacksTheVariableArityTail() throws Exception
      Throws:
      Exception
    • streamCollectResolvesTheCollectorOverload

      @Test public void streamCollectResolvesTheCollectorOverload() throws Exception
      Throws:
      Exception
    • leastUpperBoundOfIntegerAndDoubleIsNumber

      @Test public void leastUpperBoundOfIntegerAndDoubleIsNumber() throws Exception
      Throws:
      Exception
    • recursiveBoundAcceptsASubclassOfAComparable

      @Test public void recursiveBoundAcceptsASubclassOfAComparable() throws Exception
      Throws:
      Exception
    • recursiveBoundAcceptsAClassComparableThroughASuperinterface

      @Test public void recursiveBoundAcceptsAClassComparableThroughASuperinterface() throws Exception
      Throws:
      Exception
    • unboundedWildcardIsCapturedWithTheDeclaredBound

      @Test public void unboundedWildcardIsCapturedWithTheDeclaredBound() throws Exception
      Throws:
      Exception
    • unboundedWildcardOfABoundedClassSelectsTheGenericOverload

      @Test public void unboundedWildcardOfABoundedClassSelectsTheGenericOverload() throws Exception
      An unbounded wildcard of a class that declares its parameter with a bound is captured with that bound: a BoundedBoxFixtures.NumberBox<?> holds Numbers, so <T extends Number> boxed(BoundedBoxFixtures.NumberBox<T>) applies and is more specific than boxed(Object). The capture took only the wildcard's own bound, so the generic overload did not apply and the call went to boxed(Object). It was right before PR 518.
      Throws:
      Exception