[FIR, IR] Run DefaultArgumentsInExpectActualizedByFakeOverride not only in FIR but in IR as well
Review: https://jetbrains.team/p/kt/reviews/13334/timeline Thanks to the previous commit, it's now possible to run DefaultArgumentsInExpectActualizedByFakeOverride on both: frontend (FIR) and backend (IR). We aim to perform a thorough examination of checks involving fake-overrides on both FIR and IR, given their distinct implementations for handling fake-overrides. The commit decreases scope of influence of hacky `shouldCheckDefaultParams` flag.
This commit is contained in:
+17
-18
@@ -369,32 +369,31 @@ object AbstractExpectActualChecker {
|
|||||||
|
|
||||||
getTypeParametersVarianceOrReifiedIncompatibility(expectedTypeParameters, actualTypeParameters)?.let { return it }
|
getTypeParametersVarianceOrReifiedIncompatibility(expectedTypeParameters, actualTypeParameters)?.let { return it }
|
||||||
|
|
||||||
|
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitDefaultArgumentsInExpectActualizedByFakeOverride) &&
|
||||||
|
// If expect declaration is a fake-override then default params came from common
|
||||||
|
// supertypes of actual class and expect class. It's a valid code.
|
||||||
|
!expectDeclaration.isFakeOverride(expectContainingClass) &&
|
||||||
|
(actualDeclaration.isFakeOverride(actualContainingClass) || actualDeclaration.isDelegatedMember) &&
|
||||||
|
expectDeclaration.valueParameters.any { it.hasDefaultValueNonRecursive }
|
||||||
|
) {
|
||||||
|
return ExpectActualCheckingCompatibility.DefaultArgumentsInExpectActualizedByFakeOverride
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldCheckDefaultParams &&
|
if (shouldCheckDefaultParams &&
|
||||||
// "parameters" checks are required only for functions, because only functions can have parameters
|
// "parameters" checks are required only for functions, because only functions can have parameters
|
||||||
actualDeclaration is FunctionSymbolMarker && expectDeclaration is FunctionSymbolMarker
|
actualDeclaration is FunctionSymbolMarker && expectDeclaration is FunctionSymbolMarker &&
|
||||||
|
// Actual annotation constructors can have default argument values; their consistency with arguments in the expected annotation
|
||||||
|
// is checked in ExpectedActualDeclarationChecker.checkAnnotationConstructors
|
||||||
|
!actualDeclaration.isAnnotationConstructor()
|
||||||
) {
|
) {
|
||||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitDefaultArgumentsInExpectActualizedByFakeOverride) &&
|
|
||||||
// If expect declaration is a fake-override then default params came from common
|
|
||||||
// supertypes of actual class and expect class. It's a valid code.
|
|
||||||
!expectDeclaration.isFakeOverride(expectContainingClass) &&
|
|
||||||
(actualDeclaration.isFakeOverride(actualContainingClass) || actualDeclaration.isDelegatedMember) &&
|
|
||||||
expectDeclaration.valueParameters.any { it.hasDefaultValueNonRecursive }
|
|
||||||
) {
|
|
||||||
return ExpectActualCheckingCompatibility.DefaultArgumentsInExpectActualizedByFakeOverride
|
|
||||||
}
|
|
||||||
|
|
||||||
val expectOverriddenDeclarations =
|
val expectOverriddenDeclarations =
|
||||||
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(expectContainingClass).toSet()
|
expectDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(expectContainingClass).toSet()
|
||||||
val actualOverriddenDeclarations =
|
val actualOverriddenDeclarations =
|
||||||
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(actualContainingClass)
|
actualDeclaration.allRecursivelyOverriddenDeclarationsIncludingSelf(actualContainingClass)
|
||||||
|
|
||||||
// Actual annotation constructors can have default argument values; their consistency with arguments in the expected annotation
|
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
||||||
// is checked in ExpectedActualDeclarationChecker.checkAnnotationConstructors
|
// Here we filter out such default params.
|
||||||
if (!actualDeclaration.isAnnotationConstructor() &&
|
if ((actualOverriddenDeclarations - expectOverriddenDeclarations).flatMap { it.valueParameters }.any { it.hasDefaultValue }) {
|
||||||
// If default params came from common supertypes of actual class and expect class then it's a valid code.
|
|
||||||
// Here we filter out such default params.
|
|
||||||
(actualOverriddenDeclarations - expectOverriddenDeclarations).flatMap { it.valueParameters }.any { it.hasDefaultValue }
|
|
||||||
) {
|
|
||||||
return ExpectActualCheckingCompatibility.ActualFunctionWithDefaultParameters
|
return ExpectActualCheckingCompatibility.ActualFunctionWithDefaultParameters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
expect class Foo {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo {
|
||||||
fun foo(p: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(p: Int = 1)<!>
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
// MODULE: m2-jvm()()(m1-common)
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
expect class Foo {
|
||||||
|
fun foo(p: Int = 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
interface Base {
|
||||||
|
fun foo(p: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
object BaseImpl : Base {
|
||||||
|
override fun foo(p: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual class Foo : <!DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE!>Base by BaseImpl<!>
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
expect interface Foo {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect interface Foo {
|
||||||
fun foo(p: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(p: Int = 1)<!>
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
// MODULE: m2-jvm()()(m1-common)
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
expect interface Foo {
|
||||||
|
fun foo(p: Int = 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
interface Base1 {
|
||||||
|
fun foo(p: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Base2 {
|
||||||
|
fun foo(p: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING")
|
||||||
|
actual interface Foo : <!DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE!>Base1, Base2<!>
|
||||||
+5
-5
@@ -1,10 +1,10 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
expect class Foo {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo {
|
||||||
class Bar() {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>class Bar() {
|
||||||
fun foo(p: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(p: Int = 1)<!>
|
||||||
}
|
}<!>
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
// MODULE: m2-jvm()()(m1-common)
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
expect class Foo {
|
||||||
|
class Bar() {
|
||||||
|
fun foo(p: Int = 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
open class Base {
|
||||||
|
fun foo(p: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual class Foo {
|
||||||
|
actual class Bar : <!DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE!>Base()<!>
|
||||||
|
}
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
expect class Foo {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo {
|
||||||
fun foo(param: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(param: Int = 1)<!>
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
// MODULE: m2-jvm()()(m1-common)
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
expect class Foo {
|
||||||
|
fun foo(param: Int = 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
open class Base {
|
||||||
|
fun foo(param: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual class Foo : <!DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE!>Base()<!>
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo {
|
||||||
fun foo(param: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(param: Int = 1)<!>
|
||||||
<!NO_ACTUAL_FOR_EXPECT{JVM}!>fun missingOnActual()<!>
|
<!NO_ACTUAL_FOR_EXPECT{JVM}!>fun missingOnActual()<!>
|
||||||
}<!>
|
}<!>
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
expect class Foo() {
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo() {
|
||||||
fun foo(p: Int = 1)
|
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>fun foo(p: Int = 1)<!>
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
// MODULE: m2-jvm()()(m1-common)
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
expect class Foo() {
|
||||||
|
fun foo(p: Int = 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: m2-jvm()()(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
open class Base<T> {
|
||||||
|
fun foo(p: T) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual class Foo : <!DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE!>Base<Int>()<!>
|
||||||
Reference in New Issue
Block a user