[FIR] Consider expect default function parameters in FirSuperCallWithDefaultsChecker
^KT-61572 Fixed
This commit is contained in:
committed by
Space Team
parent
ec5fd02ab9
commit
89fe73f6f4
+5
-2
@@ -10,17 +10,20 @@ import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.explicitReceiverIsNotSuperReference
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.getSingleCompatibleOrWeaklyIncompatibleExpectForActualOrNull
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentList
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
|
||||
object FirSuperCallWithDefaultsChecker : FirFunctionCallChecker() {
|
||||
|
||||
override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (expression.explicitReceiverIsNotSuperReference()) return
|
||||
|
||||
val functionSymbol = expression.calleeReference.toResolvedNamedFunctionSymbol() ?: return
|
||||
if (!functionSymbol.valueParameterSymbols.any { it.hasDefaultValue }) return
|
||||
val relevantFunctionSymbol =
|
||||
(functionSymbol.getSingleCompatibleOrWeaklyIncompatibleExpectForActualOrNull() as? FirNamedFunctionSymbol) ?: functionSymbol
|
||||
if (!relevantFunctionSymbol.valueParameterSymbols.any { it.hasDefaultValue }) return
|
||||
val arguments = expression.argumentList as? FirResolvedArgumentList ?: return
|
||||
if (arguments.arguments.size < functionSymbol.valueParameterSymbols.size) {
|
||||
reporter.reportOn(
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
// KT-61572: SUPER_CALL_WITH_DEFAULT_PARAMETERS must be raised for K2/Native in fun bar1()
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
package foo
|
||||
expect open class A {
|
||||
open fun foo(x: Int = 20, y: Int = 3): Int
|
||||
}
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
package foo
|
||||
actual open class A {
|
||||
actual open fun foo(x: Int, y: Int) = x + y
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
override fun foo(x: Int, y: Int) = 0
|
||||
|
||||
fun bar1() = super.foo()
|
||||
}
|
||||
+4
-4
@@ -1,16 +1,16 @@
|
||||
// KT-61572: SUPER_CALL_WITH_DEFAULT_PARAMETERS must be raised for K2/Native in fun bar1()
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-61572
|
||||
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
package foo
|
||||
expect open class A {
|
||||
open fun foo(x: Int = 20, y: Int = 3): Int
|
||||
}
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
package foo
|
||||
|
||||
actual open class A {
|
||||
actual open fun foo(x: Int, y: Int) = x + y
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user