K2: Support callable references adaptation on top-level
^KT-45989 In progress ^KT-54709 Related ^KT-55217 Fixed
This commit is contained in:
committed by
Space Team
parent
8f8ea8c57f
commit
dcdc48a233
+16
@@ -3108,6 +3108,22 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Adapted {
|
||||
@Test
|
||||
public void testAllFilesPresentInAdapted() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleAdaptationOutsideOfCall.kt")
|
||||
public void testSimpleAdaptationOutsideOfCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/simpleAdaptationOutsideOfCall.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/callableReference/bound")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -3102,6 +3102,22 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/withQuestionMarks.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Adapted {
|
||||
@Test
|
||||
public void testAllFilesPresentInAdapted() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleAdaptationOutsideOfCall.kt")
|
||||
public void testSimpleAdaptationOutsideOfCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/simpleAdaptationOutsideOfCall.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/callableReference/bound")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
@@ -34,4 +34,9 @@ object SyntheticCallableId {
|
||||
syntheticPackageName,
|
||||
Name.identifier("ID_CALL")
|
||||
)
|
||||
|
||||
val ACCEPT_SPECIFIC_TYPE = CallableId(
|
||||
syntheticPackageName,
|
||||
Name.identifier("ACCEPT_SPECIFIC_TYPE_CALL")
|
||||
)
|
||||
}
|
||||
|
||||
+17
-17
@@ -154,34 +154,36 @@ class FirSyntheticCallGenerator(
|
||||
): FirCallableReferenceAccess? {
|
||||
val argumentList = buildUnaryArgumentList(callableReferenceAccess)
|
||||
|
||||
val typeArguments =
|
||||
val parameterTypeRef =
|
||||
when {
|
||||
expectedTypeRef is FirResolvedTypeRef && !expectedTypeRef.coneType.isUnitOrFlexibleUnit -> listOf(
|
||||
buildTypeProjectionWithVariance {
|
||||
variance = Variance.INVARIANT
|
||||
typeRef = expectedTypeRef
|
||||
}
|
||||
)
|
||||
else -> emptyList()
|
||||
expectedTypeRef is FirResolvedTypeRef && !expectedTypeRef.coneType.isUnitOrFlexibleUnit -> expectedTypeRef
|
||||
else -> context.session.builtinTypes.anyType
|
||||
}
|
||||
|
||||
val callableId = SyntheticCallableId.ACCEPT_SPECIFIC_TYPE
|
||||
val functionSymbol = FirSyntheticFunctionSymbol(callableId)
|
||||
// fun accept(p: <parameterTypeRef>): Unit
|
||||
val function =
|
||||
generateMemberFunction(functionSymbol, callableId.callableName, returnType = context.session.builtinTypes.unitType).apply {
|
||||
valueParameters += parameterTypeRef.toValueParameter("reference", functionSymbol, isVararg = false)
|
||||
}.build()
|
||||
|
||||
val reference =
|
||||
generateCalleeReferenceWithCandidate(
|
||||
callableReferenceAccess,
|
||||
idFunction,
|
||||
function,
|
||||
argumentList,
|
||||
SyntheticCallableId.ID.callableName,
|
||||
callableId.callableName,
|
||||
CallKind.SyntheticIdForCallableReferencesResolution,
|
||||
context,
|
||||
typeArguments,
|
||||
)
|
||||
val fakeCallElement = buildFunctionCall {
|
||||
calleeReference = reference
|
||||
this.argumentList = argumentList
|
||||
}
|
||||
|
||||
val argument = components.callCompleter.completeCall(fakeCallElement, expectedTypeRef).result.argument
|
||||
return ((argument as? FirVarargArgumentsExpression)?.arguments?.get(0) ?: argument) as FirCallableReferenceAccess?
|
||||
val argument = components.callCompleter.completeCall(fakeCallElement, expectedTypeRef = null).result.argument
|
||||
return argument as FirCallableReferenceAccess?
|
||||
}
|
||||
|
||||
private fun generateCalleeReferenceWithCandidate(
|
||||
@@ -191,9 +193,8 @@ class FirSyntheticCallGenerator(
|
||||
name: Name,
|
||||
callKind: CallKind = CallKind.SyntheticSelect,
|
||||
context: ResolutionContext,
|
||||
typeArguments: List<FirTypeProjection> = emptyList()
|
||||
): FirNamedReferenceWithCandidate {
|
||||
val callInfo = generateCallInfo(callSite, name, argumentList, callKind, typeArguments)
|
||||
val callInfo = generateCallInfo(callSite, name, argumentList, callKind)
|
||||
val candidate = generateCandidate(callInfo, function, context)
|
||||
val applicability = components.resolutionStageRunner.processCandidate(candidate, context)
|
||||
if (applicability <= CandidateApplicability.INAPPLICABLE) {
|
||||
@@ -224,7 +225,6 @@ class FirSyntheticCallGenerator(
|
||||
name: Name,
|
||||
argumentList: FirArgumentList,
|
||||
callKind: CallKind,
|
||||
typeArguments: List<FirTypeProjection> = emptyList()
|
||||
) = CallInfo(
|
||||
callSite = callSite,
|
||||
callKind = callKind,
|
||||
@@ -232,7 +232,7 @@ class FirSyntheticCallGenerator(
|
||||
explicitReceiver = null,
|
||||
argumentList = argumentList,
|
||||
isImplicitInvoke = false,
|
||||
typeArguments = typeArguments,
|
||||
typeArguments = emptyList(),
|
||||
session = session,
|
||||
containingFile = components.file,
|
||||
containingDeclarations = components.containingDeclarations
|
||||
|
||||
Reference in New Issue
Block a user