[FIR] If callable reference can't be resolved with expected type, try resolving with Any
In positions outside of calls (e.g. property initializers) we resolve callable references using a synthetic outer call with the expected type as parameter type. If this fails, we previously returned an unresolved reference. After this commit, we additionally try to resolve the callable reference with expected type Any. This lets us report more precise diagnostics like type mismatches or when multiple overloads exist NONE_APPLICABLE. #KT-55373 Fixed #KT-55955 Fixed
This commit is contained in:
committed by
Space Team
parent
2c91ae1129
commit
ade1354a84
+1
-1
@@ -21,5 +21,5 @@ FILE: leakedImplicitType.kt
|
||||
public final fun R|IB|.extFun(x: R|IA|): R|kotlin/Unit| {
|
||||
}
|
||||
public final fun testWithExpectedType(): R|kotlin/Unit| {
|
||||
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::<Unresolved reference: extFun>#
|
||||
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::<Ambiguity: extFun, [/extFun, /extFun]>#
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ fun IA.extFun(x: IB) {}
|
||||
fun IB.extFun(x: IA) {}
|
||||
|
||||
fun testWithExpectedType() {
|
||||
val extFun_AA_B: IA.(IA) -> Unit = IB::<!UNRESOLVED_REFERENCE!>extFun<!> // extFun is unresolved, type of IB::extFun is implicit
|
||||
val extFun_AA_B: IA.(IA) -> Unit = IB::<!NONE_APPLICABLE!>extFun<!> // extFun is unresolved, type of IB::extFun is implicit
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ FILE: moreSpecificAmbiguousExtensions.kt
|
||||
}
|
||||
public final fun testWithExpectedType(): R|kotlin/Unit| {
|
||||
lval extFun_AB_A: R|IA.(IB) -> kotlin/Unit| = Q|IA|::R|/extFun|
|
||||
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::<Unresolved reference: extFun>#
|
||||
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::<Ambiguity: extFun, [/extFun, /extFun]>#
|
||||
lval extFun_BB_A: R|IB.(IB) -> kotlin/Unit| = Q|IA|::R|/extFun|
|
||||
lval extFun_BA_B: R|IB.(IA) -> kotlin/Unit| = Q|IB|::R|/extFun|
|
||||
lval extFun_BB_B: R|IB.(IB) -> kotlin/Unit| = Q|IB|::<Ambiguity: extFun, [/extFun, /extFun]>#
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ fun test() {
|
||||
fun testWithExpectedType() {
|
||||
// NB: should be resolved to kotlin/FunctionX, not kotlin/reflect/FunctionX
|
||||
val extFun_AB_A: IA.(IB) -> Unit = IA::extFun
|
||||
val extFun_AA_B: IA.(IA) -> Unit = IB::<!UNRESOLVED_REFERENCE!>extFun<!>
|
||||
val extFun_AA_B: IA.(IA) -> Unit = IB::<!NONE_APPLICABLE!>extFun<!>
|
||||
val extFun_BB_A: IB.(IB) -> Unit = IA::extFun
|
||||
val extFun_BA_B: IB.(IA) -> Unit = IB::extFun
|
||||
val extFun_BB_B: IB.(IB) -> Unit = IB::<!OVERLOAD_RESOLUTION_AMBIGUITY!>extFun<!>
|
||||
|
||||
+6
@@ -3528,6 +3528,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt52503.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55373.kt")
|
||||
public void testKt55373() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt55373.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt7430_wrongClassOnLHS.kt")
|
||||
public void testKt7430_wrongClassOnLHS() throws Exception {
|
||||
|
||||
+6
@@ -3534,6 +3534,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt52503.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt55373.kt")
|
||||
public void testKt55373() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt55373.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt7430_wrongClassOnLHS.kt")
|
||||
public void testKt7430_wrongClassOnLHS() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user