K2: allow/disallow coercion-to-unit for callable references more precisely
Before this commit, K2 always applied coercion-to-unit for callable references if expected type was Unit, and actual non-Unit. However, this may not work in case when actual return type is a type parameter and it must be inferred into Unit. In this commit we started to disallow coercion-to-unit for references with synthetic outer call (~ top-level in K1) AND a type parameter as a return type (both should be true to disallow). This provides better K1 consistency, while still keeping some broken K1 cases working in K2. See also added comment in CallableReferenceResolution.kt. #KT-62565 Fixed
This commit is contained in:
committed by
Space Team
parent
25c0bd278e
commit
2680c8effd
+18
@@ -4833,6 +4833,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
|
||||||
|
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("annotationClassConstructor.kt")
|
@TestMetadata("annotationClassConstructor.kt")
|
||||||
public void testAnnotationClassConstructor() throws Exception {
|
public void testAnnotationClassConstructor() throws Exception {
|
||||||
@@ -17463,6 +17469,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
|
||||||
|
public void testConversionLastStatementInLambdaGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt55931.kt")
|
@TestMetadata("kt55931.kt")
|
||||||
public void testKt55931() throws Exception {
|
public void testKt55931() throws Exception {
|
||||||
@@ -17825,6 +17837,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("genericInApply.kt")
|
||||||
|
public void testGenericInApply() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
||||||
public void testIndirectCoercionWithExpectedType() throws Exception {
|
public void testIndirectCoercionWithExpectedType() throws Exception {
|
||||||
|
|||||||
+18
@@ -4833,6 +4833,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
|
||||||
|
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("annotationClassConstructor.kt")
|
@TestMetadata("annotationClassConstructor.kt")
|
||||||
public void testAnnotationClassConstructor() throws Exception {
|
public void testAnnotationClassConstructor() throws Exception {
|
||||||
@@ -17463,6 +17469,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
|
||||||
|
public void testConversionLastStatementInLambdaGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt55931.kt")
|
@TestMetadata("kt55931.kt")
|
||||||
public void testKt55931() throws Exception {
|
public void testKt55931() throws Exception {
|
||||||
@@ -17825,6 +17837,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("genericInApply.kt")
|
||||||
|
public void testGenericInApply() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
||||||
public void testIndirectCoercionWithExpectedType() throws Exception {
|
public void testIndirectCoercionWithExpectedType() throws Exception {
|
||||||
|
|||||||
+18
@@ -4827,6 +4827,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
|
||||||
|
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("annotationClassConstructor.kt")
|
@TestMetadata("annotationClassConstructor.kt")
|
||||||
public void testAnnotationClassConstructor() throws Exception {
|
public void testAnnotationClassConstructor() throws Exception {
|
||||||
@@ -17457,6 +17463,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
|
||||||
|
public void testConversionLastStatementInLambdaGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt55931.kt")
|
@TestMetadata("kt55931.kt")
|
||||||
public void testKt55931() throws Exception {
|
public void testKt55931() throws Exception {
|
||||||
@@ -17819,6 +17831,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("genericInApply.kt")
|
||||||
|
public void testGenericInApply() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
||||||
public void testIndirectCoercionWithExpectedType() throws Exception {
|
public void testIndirectCoercionWithExpectedType() throws Exception {
|
||||||
|
|||||||
+18
@@ -4833,6 +4833,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
|
||||||
|
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("annotationClassConstructor.kt")
|
@TestMetadata("annotationClassConstructor.kt")
|
||||||
public void testAnnotationClassConstructor() throws Exception {
|
public void testAnnotationClassConstructor() throws Exception {
|
||||||
@@ -17463,6 +17469,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
|
||||||
|
public void testConversionLastStatementInLambdaGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt55931.kt")
|
@TestMetadata("kt55931.kt")
|
||||||
public void testKt55931() throws Exception {
|
public void testKt55931() throws Exception {
|
||||||
@@ -17825,6 +17837,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("genericInApply.kt")
|
||||||
|
public void testGenericInApply() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
||||||
public void testIndirectCoercionWithExpectedType() throws Exception {
|
public void testIndirectCoercionWithExpectedType() throws Exception {
|
||||||
|
|||||||
@@ -375,6 +375,7 @@ class FirCallResolver(
|
|||||||
fun resolveCallableReference(
|
fun resolveCallableReference(
|
||||||
constraintSystemBuilder: ConstraintSystemBuilder,
|
constraintSystemBuilder: ConstraintSystemBuilder,
|
||||||
resolvedCallableReferenceAtom: ResolvedCallableReferenceAtom,
|
resolvedCallableReferenceAtom: ResolvedCallableReferenceAtom,
|
||||||
|
hasSyntheticOuterCall: Boolean,
|
||||||
): Pair<CandidateApplicability, Boolean> {
|
): Pair<CandidateApplicability, Boolean> {
|
||||||
val callableReferenceAccess = resolvedCallableReferenceAtom.reference
|
val callableReferenceAccess = resolvedCallableReferenceAtom.reference
|
||||||
val calleeReference = callableReferenceAccess.calleeReference
|
val calleeReference = callableReferenceAccess.calleeReference
|
||||||
@@ -383,8 +384,7 @@ class FirCallResolver(
|
|||||||
val expectedType = resolvedCallableReferenceAtom.expectedType?.let(coneSubstitutor::substituteOrSelf)
|
val expectedType = resolvedCallableReferenceAtom.expectedType?.let(coneSubstitutor::substituteOrSelf)
|
||||||
|
|
||||||
val info = createCallableReferencesInfoForLHS(
|
val info = createCallableReferencesInfoForLHS(
|
||||||
callableReferenceAccess, lhs,
|
callableReferenceAccess, lhs, expectedType, constraintSystemBuilder, hasSyntheticOuterCall
|
||||||
expectedType, constraintSystemBuilder,
|
|
||||||
)
|
)
|
||||||
// No reset here!
|
// No reset here!
|
||||||
val localCollector = CandidateCollector(components, components.resolutionStageRunner)
|
val localCollector = CandidateCollector(components, components.resolutionStageRunner)
|
||||||
@@ -685,6 +685,7 @@ class FirCallResolver(
|
|||||||
lhs: DoubleColonLHS?,
|
lhs: DoubleColonLHS?,
|
||||||
expectedType: ConeKotlinType?,
|
expectedType: ConeKotlinType?,
|
||||||
outerConstraintSystemBuilder: ConstraintSystemBuilder?,
|
outerConstraintSystemBuilder: ConstraintSystemBuilder?,
|
||||||
|
hasSyntheticOuterCall: Boolean,
|
||||||
): CallInfo {
|
): CallInfo {
|
||||||
return CallInfo(
|
return CallInfo(
|
||||||
callableReferenceAccess,
|
callableReferenceAccess,
|
||||||
@@ -703,6 +704,7 @@ class FirCallResolver(
|
|||||||
expectedType,
|
expectedType,
|
||||||
outerConstraintSystemBuilder,
|
outerConstraintSystemBuilder,
|
||||||
lhs,
|
lhs,
|
||||||
|
hasSyntheticOuterCall,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,11 @@ data class CallInfo(
|
|||||||
|
|
||||||
val candidateForCommonInvokeReceiver: Candidate? = null,
|
val candidateForCommonInvokeReceiver: Candidate? = null,
|
||||||
|
|
||||||
// Four properties for callable references only
|
// Five properties for callable references only
|
||||||
val expectedType: ConeKotlinType? = null,
|
val expectedType: ConeKotlinType? = null,
|
||||||
val outerCSBuilder: ConstraintSystemBuilder? = null,
|
val outerCSBuilder: ConstraintSystemBuilder? = null,
|
||||||
val lhs: DoubleColonLHS? = null,
|
val lhs: DoubleColonLHS? = null,
|
||||||
|
val hasSyntheticOuterCall: Boolean = false,
|
||||||
val origin: FirFunctionCallOrigin = FirFunctionCallOrigin.Regular,
|
val origin: FirFunctionCallOrigin = FirFunctionCallOrigin.Regular,
|
||||||
) : AbstractCallInfo() {
|
) : AbstractCallInfo() {
|
||||||
val arguments: List<FirExpression> get() = argumentList.arguments
|
val arguments: List<FirExpression> get() = argumentList.arguments
|
||||||
|
|||||||
+24
-9
@@ -136,18 +136,33 @@ private fun buildResultingTypeAndAdaptation(
|
|||||||
parameters += receiverType
|
parameters += receiverType
|
||||||
}
|
}
|
||||||
|
|
||||||
val returnType = callableReferenceAdaptation?.let {
|
val returnTypeWithoutCoercion = returnTypeRef.coneType
|
||||||
parameters += it.argumentTypes
|
val returnType = if (callableReferenceAdaptation == null) {
|
||||||
if (it.coercionStrategy == CoercionStrategy.COERCION_TO_UNIT) {
|
returnTypeWithoutCoercion.also {
|
||||||
context.session.builtinTypes.unitType.type
|
fir.valueParameters.mapTo(parameters) { it.returnTypeRef.coneType }
|
||||||
} else {
|
}
|
||||||
returnTypeRef.coneType
|
} else {
|
||||||
|
parameters += callableReferenceAdaptation.argumentTypes
|
||||||
|
// K1 simply doesn't perform any conversions for so-called "top level callable references",
|
||||||
|
// only for "callable reference arguments"
|
||||||
|
// (see CallableReferencesCandidateFactory.buildReflectionType, val buildTypeWithConversions)
|
||||||
|
// Here hasSyntheticOuterCall is ~ an equivalent of "top level callable references" in K1
|
||||||
|
// K2 behavior differs at least in two aspects:
|
||||||
|
// - it still allows to drop some default parameters / convert some varargs
|
||||||
|
// - see testData/diagnostics/tests/callableReference/adapted/simpleAdaptationOutsideOfCall.kt
|
||||||
|
// - see testData/diagnostics/tests/callableReference/resolve/withVararg.kt
|
||||||
|
// - coercion to unit is still allowed if a candidate return type is not type parameter based
|
||||||
|
// - see testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt
|
||||||
|
val hasSyntheticOuterCall = candidate.callInfo.hasSyntheticOuterCall
|
||||||
|
if (callableReferenceAdaptation.coercionStrategy != CoercionStrategy.COERCION_TO_UNIT ||
|
||||||
|
hasSyntheticOuterCall && returnTypeWithoutCoercion.unwrapFlexibleAndDefinitelyNotNull() is ConeTypeParameterType
|
||||||
|
) {
|
||||||
|
returnTypeWithoutCoercion
|
||||||
|
} else {
|
||||||
|
context.session.builtinTypes.unitType.type
|
||||||
}
|
}
|
||||||
} ?: returnTypeRef.coneType.also {
|
|
||||||
fir.valueParameters.mapTo(parameters) { it.returnTypeRef.coneType }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val baseFunctionTypeKind = callableReferenceAdaptation?.suspendConversionStrategy?.kind
|
val baseFunctionTypeKind = callableReferenceAdaptation?.suspendConversionStrategy?.kind
|
||||||
?: fir.specialFunctionTypeKind(context.session)
|
?: fir.specialFunctionTypeKind(context.session)
|
||||||
?: FunctionTypeKind.Function
|
?: FunctionTypeKind.Function
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.typeAliasForConstructor
|
|||||||
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.SyntheticCallableId.ACCEPT_SPECIFIC_TYPE
|
||||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||||
@@ -562,7 +563,9 @@ internal object EagerResolveOfCallableReferences : CheckerStage() {
|
|||||||
for (atom in candidate.postponedAtoms) {
|
for (atom in candidate.postponedAtoms) {
|
||||||
if (atom is ResolvedCallableReferenceAtom) {
|
if (atom is ResolvedCallableReferenceAtom) {
|
||||||
val (applicability, success) =
|
val (applicability, success) =
|
||||||
context.bodyResolveComponents.callResolver.resolveCallableReference(candidate.csBuilder, atom)
|
context.bodyResolveComponents.callResolver.resolveCallableReference(
|
||||||
|
candidate.csBuilder, atom, hasSyntheticOuterCall = candidate.callInfo.name == ACCEPT_SPECIFIC_TYPE.callableName
|
||||||
|
)
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// If the resolution was unsuccessful, we ensure that an error will be reported for the callable reference
|
// If the resolution was unsuccessful, we ensure that an error will be reported for the callable reference
|
||||||
// during completion by using the `resultingReference` of the postponed atom.
|
// during completion by using the `resultingReference` of the postponed atom.
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
|
|
||||||
private fun processCallableReference(atom: ResolvedCallableReferenceAtom, candidate: Candidate) {
|
private fun processCallableReference(atom: ResolvedCallableReferenceAtom, candidate: Candidate) {
|
||||||
if (atom.mightNeedAdditionalResolution) {
|
if (atom.mightNeedAdditionalResolution) {
|
||||||
callResolver.resolveCallableReference(candidate.csBuilder, atom)
|
callResolver.resolveCallableReference(candidate.csBuilder, atom, hasSyntheticOuterCall = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val callableReferenceAccess = atom.reference
|
val callableReferenceAccess = atom.reference
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
fun foo(x: Int, y: Any): Int = x
|
||||||
|
|
||||||
|
fun <T> bar(x: T, y: Any): T = x
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val fooRef: (Int, Any) -> Unit = ::foo
|
||||||
|
val barRef: (Int, Any) -> Unit = ::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>
|
||||||
|
}
|
||||||
compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
fun foo(x: Int, y: Any): Int = x
|
||||||
|
|
||||||
|
fun <T> bar(x: T, y: Any): T = x
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val fooRef: (Int, Any) -> Unit = <!TYPE_MISMATCH!>::<!TYPE_MISMATCH!>foo<!><!>
|
||||||
|
val barRef: (Int, Any) -> Unit = <!TYPE_MISMATCH!>::<!TYPE_MISMATCH!>bar<!><!>
|
||||||
|
}
|
||||||
+2
-2
@@ -11,7 +11,7 @@ class A1 {
|
|||||||
class A2 {
|
class A2 {
|
||||||
fun <K, V> a2(key: K): V = TODO()
|
fun <K, V> a2(key: K): V = TODO()
|
||||||
|
|
||||||
fun test1(): (String) -> Unit = A2()::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a2<!>
|
fun test1(): (String) -> Unit = A2()::a2
|
||||||
fun <T3> test2(): (T3) -> T3 = A2()::a2
|
fun <T3> test2(): (T3) -> T3 = A2()::a2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class A3<T> {
|
|||||||
fun <V> a3(key: T): V = TODO()
|
fun <V> a3(key: T): V = TODO()
|
||||||
|
|
||||||
fun test1(): (T) -> Int = this::a3
|
fun test1(): (T) -> Int = this::a3
|
||||||
fun test2(): (T) -> Unit = A3<T>()::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a3<!>
|
fun test2(): (T) -> Unit = A3<T>()::a3
|
||||||
fun test3(): (Int) -> String = A3<Int>()::a3
|
fun test3(): (Int) -> String = A3<Int>()::a3
|
||||||
|
|
||||||
fun <R> test4(): (R) -> Unit = <!RETURN_TYPE_MISMATCH!>this::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a3<!><!>
|
fun <R> test4(): (R) -> Unit = <!RETURN_TYPE_MISMATCH!>this::<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a3<!><!>
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
// DIAGNOSTICS: -UNCHECKED_CAST
|
||||||
|
// This test is a copy of conversionLastStatementInLambda, but with generic functions
|
||||||
|
// However works diffirently in K1
|
||||||
|
|
||||||
|
fun main(b: Boolean) {
|
||||||
|
callWithLambda {
|
||||||
|
::test1
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
if (b) ::test1 else ::test2
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
if (b) {
|
||||||
|
::test1
|
||||||
|
} else {
|
||||||
|
::test2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
(::test1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> test1(): T = "" as T
|
||||||
|
fun <T> test2(): T = "" as T
|
||||||
|
|
||||||
|
fun callWithLambda(action: () -> () -> Unit) {}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
// DIAGNOSTICS: -UNCHECKED_CAST
|
||||||
|
// This test is a copy of conversionLastStatementInLambda, but with generic functions
|
||||||
|
// However works diffirently in K1
|
||||||
|
|
||||||
|
fun main(b: Boolean) {
|
||||||
|
callWithLambda {
|
||||||
|
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::test1<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
if (b) <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::test1<!> else <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::test2<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
if (b) {
|
||||||
|
::test1
|
||||||
|
} else {
|
||||||
|
::test2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callWithLambda {
|
||||||
|
(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::test1<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> test1(): T = "" as T
|
||||||
|
fun <T> test2(): T = "" as T
|
||||||
|
|
||||||
|
fun callWithLambda(action: () -> () -> Unit) {}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// WITH_STDLIB
|
||||||
|
|
||||||
|
fun <N : Number> addNumber(n: N) = n
|
||||||
|
|
||||||
|
fun foo() = 42
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo().apply(::addNumber)
|
||||||
|
}
|
||||||
Generated
+18
@@ -4833,6 +4833,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("ambiguityTopLevelVsTopLevelGeneric.kt")
|
||||||
|
public void testAmbiguityTopLevelVsTopLevelGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/function/ambiguityTopLevelVsTopLevelGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("annotationClassConstructor.kt")
|
@TestMetadata("annotationClassConstructor.kt")
|
||||||
public void testAnnotationClassConstructor() throws Exception {
|
public void testAnnotationClassConstructor() throws Exception {
|
||||||
@@ -17463,6 +17469,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("conversionLastStatementInLambdaGeneric.kt")
|
||||||
|
public void testConversionLastStatementInLambdaGeneric() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambdaGeneric.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt55931.kt")
|
@TestMetadata("kt55931.kt")
|
||||||
public void testKt55931() throws Exception {
|
public void testKt55931() throws Exception {
|
||||||
@@ -17825,6 +17837,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/coersionWithAnonymousFunctionsAndUnresolved.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("genericInApply.kt")
|
||||||
|
public void testGenericInApply() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/genericInApply.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
@TestMetadata("indirectCoercionWithExpectedType.kt")
|
||||||
public void testIndirectCoercionWithExpectedType() throws Exception {
|
public void testIndirectCoercionWithExpectedType() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user