Fix ambiguity on callable reference for expect members
Expect members should always lose in resolution to non-expect members, be it simple calls or callable references. Note that there should be exactly one actual member for each expect member in correct code, so both ways to check for expect vs non-expect are correct: either before signature comparison, or after. #KT-20903 Fixed
This commit is contained in:
+10
-1
@@ -352,7 +352,16 @@ open class OverloadingConflictResolver<C : Any>(
|
||||
|
||||
val fSignature = FlatSignature.createFromCallableDescriptor(f)
|
||||
val gSignature = FlatSignature.createFromCallableDescriptor(g)
|
||||
return createEmptyConstraintSystem().isSignatureNotLessSpecific(fSignature, gSignature, SpecificityComparisonWithNumerics, specificityComparator)
|
||||
if (!createEmptyConstraintSystem().isSignatureNotLessSpecific(fSignature, gSignature, SpecificityComparisonWithNumerics, specificityComparator)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (f is CallableMemberDescriptor && g is CallableMemberDescriptor) {
|
||||
if (!f.isExpect && g.isExpect) return true
|
||||
if (f.isExpect && !g.isExpect) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun isNotLessSpecificCallableReference(f: CallableDescriptor, g: CallableDescriptor): Boolean =
|
||||
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
package test
|
||||
|
||||
expect fun foo(): String
|
||||
|
||||
fun g(f: () -> String): String = f()
|
||||
|
||||
fun test() {
|
||||
g(::<!JVM:DEPRECATION!>foo<!>)
|
||||
}
|
||||
|
||||
// MODULE: m2-jvm(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
package test
|
||||
|
||||
@Deprecated("To check that ::foo is resolved to actual fun foo when compiling common+jvm")
|
||||
actual fun foo(): String = ""
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// -- Module: <m1-common> --
|
||||
package
|
||||
|
||||
package test {
|
||||
public expect fun foo(): kotlin.String
|
||||
public fun g(/*0*/ f: () -> kotlin.String): kotlin.String
|
||||
public fun test(): kotlin.Unit
|
||||
}
|
||||
|
||||
|
||||
// -- Module: <m2-jvm> --
|
||||
package
|
||||
|
||||
package test {
|
||||
@kotlin.Deprecated(message = "To check that ::foo is resolved to actual fun foo when compiling common+jvm") public actual fun foo(): kotlin.String
|
||||
public fun g(/*0*/ f: () -> kotlin.String): kotlin.String
|
||||
public fun test(): kotlin.Unit
|
||||
}
|
||||
@@ -14355,6 +14355,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceOnExpectFun.kt")
|
||||
public void testCallableReferenceOnExpectFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingHeaderDeclarations.kt")
|
||||
public void testConflictingHeaderDeclarations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.kt");
|
||||
|
||||
+6
@@ -14355,6 +14355,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceOnExpectFun.kt")
|
||||
public void testCallableReferenceOnExpectFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/callableReferenceOnExpectFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingHeaderDeclarations.kt")
|
||||
public void testConflictingHeaderDeclarations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingHeaderDeclarations.kt");
|
||||
|
||||
Reference in New Issue
Block a user