Class OverloadSelectionTck
java.lang.Object
io.micronaut.sourcegen.bytecode.tck.AbstractByteCodeWriterTck
io.micronaut.sourcegen.bytecode.tck.OverloadSelectionTck
Overload selection: the phases of strict, loose and variable arity invocation, the most specific
method, accessibility of candidates and explicit descriptors. Each generated call must choose the
overload javac chooses for the same 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConstructors with different access levels.static classPublic alternatives to inaccessible overloads.static classA fixed arity array declaration.static classArray covariance control.static classClass satisfying both intersection bounds.static classImplements both intersection bounds.static classBoth bounds.static classImplements both return descriptors.static classBoth bounds.static classReflected generic overloads.static interfaceInherited covariant declarations.static classImplementation used by the independent oracle.static interfaceFirst overloaded intersection bound.static classGeneric class with a class-variable overload and an Object fallback.static interfaceCovariant receiver bound.static interfaceNarrow covariant declaration.static interfaceCovariant receiver bound.static classAn overload of a superclass.static classReflected overloads with observably different results.static classA public and a package-private overload.static classA public and a protected overload.static classThe javac-compiled subclass calling the overloads.static classOverloads whose specificity changes when the receiver is parameterized.static interfaceSecond overloaded intersection bound.static classReceiver specialized through inheritance.static classGeneric receiver with a concrete overload.static interfaceAn overload of an interface.static classBoth.static classVarargs overload controls.static interfaceWide covariant declaration.static classA public and a protected overload taking a supertype of the argument.static classThe javac-compiled subclass calling the overloads through a receiver of its own type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidGeneric overloads in generated definitions are distinguished by the complete bound chain.voidvoidvoidvoidvoidgeneratedOverloadsKeepLongDependentBounds(int length) A generated overload whose parameter is bounded through a long chain of dependent variables stays more specific than an overload taking Object.voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidprimitiveArgumentChoosesJavacsOverload(String method, TypeDef type, Object argument, Object expected) A single primitive or boxed argument converts to the parameter of the overload javac chooses: primitive widening in the strict phase, and unboxing followed by widening in the loose phase.voidvoidvoidvoidvoidvoidvoidvoidreflectedOverloadCallChoosesJavacsOverload(String method, ExpressionDef argument, String expected) A call by name of a reflected overloaded method chooses the overload javac chooses for the same argument.voidvoidvoidvoidvoidvoidvoidvoidvariableArityCallChoosesJavacsOverload(String method, List<TypeDef> types, List<?> arguments, Object expected) A variable arity call chooses the overload javac chooses and packs, widens or boxes its elements as javac does, while an array argument is passed as the array itself by strict invocation.Methods inherited from class AbstractByteCodeWriterTck
assertCall, caller, callWithParameter, classShape, declaredFields, declaredMethods, define, defineInPackage, genericShape, invoke, list, load, outcome, run, run, run, selection, selection, shape, write
-
Constructor Details
-
OverloadSelectionTck
public OverloadSelectionTck()
-
-
Method Details
-
reflectedOverloadCallChoosesJavacsOverload
@ParameterizedTest(name="{0}") @MethodSource("reflectedOverloadCalls") public void reflectedOverloadCallChoosesJavacsOverload(String method, ExpressionDef argument, String expected) throws Exception A call by name of a reflected overloaded method chooses the overload javac chooses for the same argument.- Parameters:
method- The overloaded method ofOverloadSelectionTck.Overloadsargument- The argument of the callexpected- The overload javac chooses, as the value it returns- Throws:
Exception- If the generated call cannot be loaded or invoked
-
explicitDescriptorSelectsRequestedOverload
-
choosesMostSpecificConstructor
-
generatedOverloadChoosesMostSpecificSupertype
-
generatedOverloadChoosesPrimitiveWidening
-
parameterizedReceiverParticipatesInOverloadSelection
-
genericIntersectionConstrainsOverloadApplicability
-
parameterizedArgumentsConstrainOverloadApplicability
-
inaccessibleMethodIsNotAnOverloadCandidate
-
secondaryBoundOverloadsUseTheFullDescriptor
-
generatedConstructorChoosesMostSpecificSupertype
-
inaccessibleConstructorIsNotAnOverloadCandidate
-
reflectedVarargsChooseMostSpecificWithNoArguments
-
reflectedVarargsPackPrimitiveArguments
-
fixedArrayMethodReceivesNullWithoutPacking
-
reflectedOverloadAcceptsCovariantArrays
-
typedNullUsesItsDeclaredTypeForOverloadSelection
-
generatedPrivateOverloadIsNotCallableFromAnotherClass
-
intersectionReceiverChoosesMatchingReturnDescriptor
-
generatedPrivateConstructorIsNotCallableFromAnotherClass
-
generatedBoundedOverloadRetainsCalleeVariables
-
primitiveWideningAndBoxingRemainOrdered
-
packagePrivateReflectedOverloadIsNotAccessible
-
protectedReflectedOverloadIsNotAccessible
-
packagePrivateOverloadAmbiguousWithAnAccessibleOneIsNotAccessible
-
packagePrivateConstructorIsNotAccessibleToASuperCall
-
protectedConstructorIsAccessibleToASuperCall
-
packagePrivateConstructorIsNotAccessible
-
protectedConstructorIsNotAccessible
-
concreteOverloadOutranksAWiderReceiverInstantiation
-
requestedGenericReturnKeepsTheMostSpecificOverload
-
parameterizedClassArgumentsChooseTheGenericConstructorOverload
-
inheritedGenericOverloadDoesNotHideTheSpecializedDeclaration
-
generatedInterfaceMethodsParticipateInOverloads
-
generatedDependentBoundsDoNotCollapseOverloadDescriptors
@ParameterizedTest(name="with the {0} overload declared first, the dependent bound keeps its own descriptor") @ValueSource(strings={"bounded","object"}) public void generatedDependentBoundsDoNotCollapseOverloadDescriptors(String order) throws Exception Generic overloads in generated definitions are distinguished by the complete bound chain. Both declaration orders are checked, to detect accidental first-candidate selection.- Parameters:
order- Which overload the generated class declares first- Throws:
Exception- If the generated program cannot be loaded or invoked
-
boundedArgumentCanSelectAnOverloadOnItsSecondaryBound
-
generatedMethodOverloadsHaveDistinctBoundedDescriptors
-
generatedClassOverloadsHaveDistinctBoundedDescriptors
-
mostSpecificMethodResolvesDependentVariableBounds
-
generatedOverloadsKeepLongDependentBounds
@ParameterizedTest(name="an overload bounded through a chain of {0} variables is more specific than Object") @ValueSource(ints={4,8,16,32}) public void generatedOverloadsKeepLongDependentBounds(int length) throws Exception A generated overload whose parameter is bounded through a long chain of dependent variables stays more specific than an overload taking Object.- Parameters:
length- The number of variables in the chain- Throws:
Exception- If the generated program cannot be loaded or invoked
-
inheritedCovariantInterfaceMethodsAreOneOverload
-
secondaryMethodBoundConstrainsMostSpecificOverload
-
differentVarargsAritiesChooseTheMostSpecificElement
-
primitiveArgumentChoosesJavacsOverload
@ParameterizedTest(name="{0}") @MethodSource("primitiveArgumentCalls") public void primitiveArgumentChoosesJavacsOverload(String method, TypeDef type, Object argument, Object expected) throws Exception A single primitive or boxed argument converts to the parameter of the overload javac chooses: primitive widening in the strict phase, and unboxing followed by widening in the loose phase.- Parameters:
method- The overloaded method ofOverloadFixtures.Callstype- The type of the argumentargument- The argumentexpected- javac's own call of the same overload with the same argument- Throws:
Exception- If the generated call cannot be loaded or invoked
-
nullPrefersCharArrayOverObject
-
variableArityCallChoosesJavacsOverload
@ParameterizedTest(name="{0}") @MethodSource("variableArityCalls") public void variableArityCallChoosesJavacsOverload(String method, List<TypeDef> types, List<?> arguments, Object expected) throws Exception A variable arity call chooses the overload javac chooses and packs, widens or boxes its elements as javac does, while an array argument is passed as the array itself by strict invocation.- Parameters:
method- The overloaded method ofOverloadFixtures.Callstypes- The types of the argumentsarguments- The argumentsexpected- javac's own call of the same overload with the same arguments- Throws:
Exception- If the generated call cannot be loaded or invoked
-
nonGenericOverloadIsMoreSpecificThanAGenericOne
-
protectedOverloadIsMoreSpecificFromASubclass
-
packagePrivateOverloadIsMoreSpecificFromTheSamePackage
-
protectedOverloadIsMoreSpecificThroughAReceiverOfTheSubclass
-
genuinelyAmbiguousCallIsRejected
@Test public void genuinelyAmbiguousCallIsRejected() -
intersectionReceiverChoosesTheMostSpecificOverloadOfAnyBound
-
intersectionReceiverSkipsAnInapplicableFirstBound
-
overloadsOfASuperclassAndAnInterfaceCompete
-