K2: repeat K1 logic around SAM-based candidates discrimination
#KT-56614 Fixed
This commit is contained in:
committed by
Space Team
parent
ce381f335d
commit
0fba58eee7
+1
-1
@@ -14,7 +14,7 @@ FILE: package2.kt
|
|||||||
}
|
}
|
||||||
FILE: main.kt
|
FILE: main.kt
|
||||||
public final fun main(): R|kotlin/Unit| {
|
public final fun main(): R|kotlin/Unit| {
|
||||||
R|p2/bar|(String(), String(), <L> = bar@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline> {
|
R|p1/bar|(String(), String(), <L> = bar@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline> {
|
||||||
^@bar Unit
|
^@bar Unit
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+11
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isFun
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isInfix
|
import org.jetbrains.kotlin.fir.declarations.utils.isInfix
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
@@ -486,8 +487,17 @@ internal object CheckArguments : CheckerStage() {
|
|||||||
sink.yieldDiagnostic(InapplicableCandidate)
|
sink.yieldDiagnostic(InapplicableCandidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logic description: only candidates from Kotlin, but using Java SAM types, are discriminated
|
||||||
candidate.usesSAM && !candidate.isJavaApplicableCandidate() -> {
|
candidate.usesSAM && !candidate.isJavaApplicableCandidate() -> {
|
||||||
sink.markCandidateForCompatibilityResolve(context)
|
if (argumentMapping.values.any {
|
||||||
|
val coneType = it.returnTypeRef.coneType
|
||||||
|
context.bodyResolveComponents.samResolver.isSamType(coneType) &&
|
||||||
|
// Candidate is not from Java, so no flexible types are possible here
|
||||||
|
coneType.toRegularClassSymbol(context.session)?.isJavaOrEnhancement == true
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
sink.markCandidateForCompatibilityResolve(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-2
@@ -12,7 +12,7 @@ object Test1 {
|
|||||||
fun foo(r: KRunnable) {}
|
fun foo(r: KRunnable) {}
|
||||||
|
|
||||||
fun test(f: () -> Unit) {
|
fun test(f: () -> Unit) {
|
||||||
<!DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!>foo(f)<!>
|
<!DEBUG_INFO_CALL("fqName: Test1.Scope.foo; typeCall: function")!>foo(f)<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ object Test3 {
|
|||||||
|
|
||||||
fun test(f: () -> Unit) {
|
fun test(f: () -> Unit) {
|
||||||
val result = foo(1, f)
|
val result = foo(1, f)
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>result<!>
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>result<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ object Test1 {
|
|||||||
fun call(r: SuspendRunnable) {}
|
fun call(r: SuspendRunnable) {}
|
||||||
|
|
||||||
fun bar(f: () -> Unit) {
|
fun bar(f: () -> Unit) {
|
||||||
<!DEBUG_INFO_CALL("fqName: Test1.call; typeCall: function")!>call(f)<!>
|
<!DEBUG_INFO_CALL("fqName: Test1.Scope.call; typeCall: function")!>call(f)<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user