[K2, MPP] Forbid matching actual callable with dynamic return type
to expect callable with non-dynamic return type ^KT-59251 Fixed
This commit is contained in:
committed by
Space Team
parent
452e67f0e6
commit
d9b5d37baf
+5
-2
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.expectForActual
|
||||
import org.jetbrains.kotlin.fir.declarations.getSingleExpectForActualOrNull
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isActual
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
@@ -45,7 +47,8 @@ object FirActualCallableDeclarationChecker : FirCallableDeclarationChecker() {
|
||||
if (!areCompatibleExpectActualTypes(
|
||||
substitutor.substituteOrSelf(expectFunctionSymbol.resolvedReturnType.type),
|
||||
actualFunctionSymbol.resolvedReturnType.type,
|
||||
context.session
|
||||
context.session,
|
||||
dynamicTypesEqualToAnything = false
|
||||
)
|
||||
) {
|
||||
reporter.reportOn(
|
||||
|
||||
@@ -34,11 +34,20 @@ fun createExpectActualTypeParameterSubstitutor(
|
||||
fun areCompatibleExpectActualTypes(
|
||||
expectedType: ConeKotlinType?,
|
||||
actualType: ConeKotlinType?,
|
||||
actualSession: FirSession
|
||||
actualSession: FirSession,
|
||||
dynamicTypesEqualToAnything: Boolean = true
|
||||
): Boolean {
|
||||
if (expectedType == null) return actualType == null
|
||||
if (actualType == null) return false
|
||||
|
||||
if (!dynamicTypesEqualToAnything) {
|
||||
val isExpectedDynamic = expectedType is ConeDynamicType
|
||||
val isActualDynamic = actualType is ConeDynamicType
|
||||
if (isExpectedDynamic && !isActualDynamic || !isExpectedDynamic && isActualDynamic) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return AbstractTypeChecker.equalTypes(
|
||||
actualSession.typeContext,
|
||||
expectedType,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// !DIAGNOSTICS: -UNSUPPORTED
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo {
|
||||
constructor(p: Any)
|
||||
|
||||
fun f1(s: String): Int
|
||||
|
||||
fun f2(s: List<String>?): MutableMap<Boolean?, Foo>
|
||||
|
||||
fun <T : Set<Number>> f3(t: T): T?
|
||||
}
|
||||
|
||||
// MODULE: m2-js()()(m1-common)
|
||||
// FILE: js.kt
|
||||
|
||||
// TODO: do not suppress UNSUPPORTED once JS files in multi-platform tests are analyzed with JS analyzer facade
|
||||
|
||||
actual class Foo {
|
||||
actual constructor(p: dynamic) {}
|
||||
|
||||
actual fun <!ACTUAL_WITHOUT_EXPECT!>f1<!>(s: dynamic): dynamic = null!!
|
||||
|
||||
actual fun f2(s: dynamic): MutableMap<Boolean?, Foo> = null!!
|
||||
|
||||
actual fun <T : Set<Number>> <!ACTUAL_WITHOUT_EXPECT!>f3<!>(t: T): dynamic = null!!
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNSUPPORTED
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
Reference in New Issue
Block a user