Skip to content

Commit 22b9d50

Browse files
nikitabobkoSpace Team
authored and
Space Team
committed
[FE 1.0] 2/2 Don't report a warning when new members are added to open expect actualization
^KT-62655 Fixed
1 parent 29cf556 commit 22b9d50

File tree

54 files changed

+161
-443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+161
-443
lines changed

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,6 @@ public interface Errors {
843843
DiagnosticFactory3<KtClassLikeDeclaration, ClassifierDescriptorWithTypeParameters, Set<ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>, ClassDescriptor>
844844
ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING =
845845
DiagnosticFactory3.create(WARNING, DECLARATION_NAME);
846-
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
847-
NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
848846
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
849847
UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
850848
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno
403403
CAPITALIZED_DECLARATION_NAME_WITH_KIND_AND_PLATFORM,
404404
ExpectActualScopeDiffsRenderer.TEXT,
405405
NAME);
406-
MAP.put(NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING,
407-
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
408-
ExpectActualScopeDiffRenderer.INSTANCE);
409406
MAP.put(UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING,
410407
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
411408
ExpectActualScopeDiffRenderer.INSTANCE);

compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.config.LanguageFeature
99
import org.jetbrains.kotlin.descriptors.*
1010
import org.jetbrains.kotlin.diagnostics.Errors
1111
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
12-
import org.jetbrains.kotlin.name.FqName
1312
import org.jetbrains.kotlin.psi.*
1413
import org.jetbrains.kotlin.resolve.BindingTrace
1514
import org.jetbrains.kotlin.resolve.calls.mpp.AbstractExpectActualCompatibilityChecker
@@ -126,7 +125,7 @@ private fun calculateExpectActualScopeDiff(
126125
return actualClassCallables.flatMap { actualMember ->
127126
val potentialExpects = nameAndKindToExpectCallables[actualMember.name to actualMember.functionVsPropertyKind]
128127
if (potentialExpects.isNullOrEmpty()) {
129-
listOf(ExpectActualMemberDiff.Kind.NonPrivateCallableAdded)
128+
emptyList<ExpectActualMemberDiff.Kind>()
130129
} else {
131130
potentialExpects
132131
.map { expectMember ->
@@ -141,9 +140,19 @@ private fun calculateExpectActualScopeDiff(
141140
}
142141
.takeIf { kinds -> kinds.all { it != ExpectActualCompatibility.Compatible } }
143142
.orEmpty()
144-
.map {
143+
.mapNotNull {
145144
when (it) {
146145
is ExpectActualCompatibility.Compatible -> error("Compatible was filtered out by takeIf")
146+
ExpectActualCompatibility.Incompatible.CallableKind,
147+
ExpectActualCompatibility.Incompatible.ParameterCount,
148+
ExpectActualCompatibility.Incompatible.ParameterShape,
149+
ExpectActualCompatibility.Incompatible.ParameterTypes,
150+
ExpectActualCompatibility.Incompatible.FunctionTypeParameterCount,
151+
ExpectActualCompatibility.Incompatible.FunctionTypeParameterUpperBounds,
152+
// Don't report "matching" (aka "strong") incompatibilities, because it's
153+
// incompatibilities that happen only when a new member added
154+
-> null
155+
147156
is ExpectActualCompatibility.Incompatible -> it.toMemberDiffKind()
148157
// If toMemberDiffKind returns null then some Kotlin invariants described in toMemberDiffKind no longer hold.
149158
// We can't throw exception here because it would crash the compilation.
@@ -180,8 +189,6 @@ private val CallableMemberDescriptor.psiIfReal: KtCallableDeclaration?
180189
private fun BindingTrace.reportIfPossible(diff: ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>) {
181190
val psi = diff.actualMember.psiIfReal ?: return
182191
val diagnostic = when (diff.kind) {
183-
ExpectActualMemberDiff.Kind.NonPrivateCallableAdded ->
184-
Errors.NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
185192
ExpectActualMemberDiff.Kind.ReturnTypeChangedInOverride ->
186193
Errors.RETURN_TYPE_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
187194
ExpectActualMemberDiff.Kind.ModalityChangedInOverride ->

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/actualTypealias.fir.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/actualTypealias.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -9,11 +10,11 @@ expect open class Foo {
910
// MODULE: m2-jvm()()(m1-common)
1011
// FILE: jvm.kt
1112

12-
actual typealias <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>Foo<!> = FooImpl
13+
actual typealias Foo = FooImpl
1314

1415
open class FooImpl {
1516
fun existingMethod() {}
1617
val existingParam: Int = 904
1718

18-
fun injectedMethod() {} // accidential override can happen with this injected fun. That's why it's prohibited
19+
fun injectedMethod() {}
1920
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectExtensionReceiverOverload.fir.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectExtensionReceiverOverload.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -8,8 +9,8 @@ expect open class Foo {
89
// MODULE: m2-jvm()()(m1-common)
910
// FILE: jvm.kt
1011

11-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
12+
actual open class Foo {
1213
actual fun foo() {}
1314

14-
fun Int.<!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>() {} // accidential override can happen with this injected fun. That's why it's prohibited
15+
fun Int.foo() {}
1516
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectGenericUpperBoundOverload.fir.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectGenericUpperBoundOverload.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -10,6 +11,6 @@ expect open class Foo : Base
1011
// MODULE: m2-jvm()()(m1-common)
1112
// FILE: jvm.kt
1213

13-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> : Base() {
14-
fun <T : Comparable<T>> <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(t: T) {}
14+
actual open class Foo : Base() {
15+
fun <T : Comparable<T>> foo(t: T) {}
1516
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_internalMethod.fir.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_internalMethod.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -9,9 +10,9 @@ expect open class Foo {
910
// MODULE: m2-jvm()()(m1-common)
1011
// FILE: jvm.kt
1112

12-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
13+
actual open class Foo {
1314
actual fun existingMethod() {}
1415
actual val existingParam: Int = 904
1516

16-
internal fun <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>injectedMethod<!>() {} // accidential override can happen with this injected fun. That's why it's prohibited
17+
internal fun injectedMethod() {}
1718
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_protectedMethod.fir.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_protectedMethod.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -9,9 +10,9 @@ expect open class Foo {
910
// MODULE: m2-jvm()()(m1-common)
1011
// FILE: jvm.kt
1112

12-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
13+
actual open class Foo {
1314
actual fun existingMethod() {}
1415
actual val existingParam: Int = 904
1516

16-
protected fun <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>injectedMethod<!>() {} // accidential override can happen with this injected fun. That's why it's prohibited
17+
protected fun injectedMethod() {}
1718
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_publicMethod.fir.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_publicMethod.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -9,9 +10,9 @@ expect open class Foo {
910
// MODULE: m2-jvm()()(m1-common)
1011
// FILE: jvm.kt
1112

12-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
13+
actual open class Foo {
1314
actual fun existingMethod() {}
1415
actual val existingParam: Int = 904
1516

16-
fun <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>injectedMethod<!>() {} // accidential override can happen with this injected fun. That's why it's prohibited
17+
fun injectedMethod() {}
1718
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_publicMethodInJava.fir.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectMethod_publicMethodInJava.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -8,7 +9,7 @@ expect open class Foo {
89
// MODULE: m2-jvm()()(m1-common)
910
// FILE: jvm.kt
1011

11-
actual typealias <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>Foo<!> = FooImpl
12+
actual typealias Foo = FooImpl
1213

1314
// FILE: Foo.java
1415

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectParameterOverload.fir.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectParameterOverload.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -8,8 +9,8 @@ expect open class Foo {
89
// MODULE: m2-jvm()()(m1-common)
910
// FILE: jvm.kt
1011

11-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
12+
actual open class Foo {
1213
actual fun foo() {}
1314

14-
fun <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(overloaded: Int) {} // accidential override can happen with this injected fun. That's why it's prohibited
15+
fun foo(overloaded: Int) {}
1516
}

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectParameterOverloadWithGenerics.fir.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectParameterOverloadWithGenerics.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// MODULE: m1-common
23
// FILE: common.kt
34

@@ -10,6 +11,6 @@ expect open class Foo<R> : Base<R>
1011
// MODULE: m2-jvm()()(m1-common)
1112
// FILE: jvm.kt
1213

13-
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!><R>() : Base<R>() {
14-
fun <T> <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(t: T) {}
14+
actual open class Foo<R>() : Base<R>() {
15+
fun <T> foo(t: T) {}
1516
}

0 commit comments

Comments
 (0)