Skip to content

Commit

Permalink
[FE 1.0] 2/2 Don't report a warning when new members are added to ope…
Browse files Browse the repository at this point in the history
…n expect actualization

^KT-62655 Fixed
  • Loading branch information
nikitabobko authored and qodana-bot committed Oct 20, 2023
1 parent 29cf556 commit 22b9d50
Show file tree
Hide file tree
Showing 54 changed files with 161 additions and 443 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,6 @@ public interface Errors {
DiagnosticFactory3<KtClassLikeDeclaration, ClassifierDescriptorWithTypeParameters, Set<ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>, ClassDescriptor>
ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING =
DiagnosticFactory3.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,6 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno
CAPITALIZED_DECLARATION_NAME_WITH_KIND_AND_PLATFORM,
ExpectActualScopeDiffsRenderer.TEXT,
NAME);
MAP.put(NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING,
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
ExpectActualScopeDiffRenderer.INSTANCE);
MAP.put(UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING,
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
ExpectActualScopeDiffRenderer.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.calls.mpp.AbstractExpectActualCompatibilityChecker
Expand Down Expand Up @@ -126,7 +125,7 @@ private fun calculateExpectActualScopeDiff(
return actualClassCallables.flatMap { actualMember ->
val potentialExpects = nameAndKindToExpectCallables[actualMember.name to actualMember.functionVsPropertyKind]
if (potentialExpects.isNullOrEmpty()) {
listOf(ExpectActualMemberDiff.Kind.NonPrivateCallableAdded)
emptyList<ExpectActualMemberDiff.Kind>()
} else {
potentialExpects
.map { expectMember ->
Expand All @@ -141,9 +140,19 @@ private fun calculateExpectActualScopeDiff(
}
.takeIf { kinds -> kinds.all { it != ExpectActualCompatibility.Compatible } }
.orEmpty()
.map {
.mapNotNull {
when (it) {
is ExpectActualCompatibility.Compatible -> error("Compatible was filtered out by takeIf")
ExpectActualCompatibility.Incompatible.CallableKind,
ExpectActualCompatibility.Incompatible.ParameterCount,
ExpectActualCompatibility.Incompatible.ParameterShape,
ExpectActualCompatibility.Incompatible.ParameterTypes,
ExpectActualCompatibility.Incompatible.FunctionTypeParameterCount,
ExpectActualCompatibility.Incompatible.FunctionTypeParameterUpperBounds,
// Don't report "matching" (aka "strong") incompatibilities, because it's
// incompatibilities that happen only when a new member added
-> null

is ExpectActualCompatibility.Incompatible -> it.toMemberDiffKind()
// If toMemberDiffKind returns null then some Kotlin invariants described in toMemberDiffKind no longer hold.
// We can't throw exception here because it would crash the compilation.
Expand Down Expand Up @@ -180,8 +189,6 @@ private val CallableMemberDescriptor.psiIfReal: KtCallableDeclaration?
private fun BindingTrace.reportIfPossible(diff: ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>) {
val psi = diff.actualMember.psiIfReal ?: return
val diagnostic = when (diff.kind) {
ExpectActualMemberDiff.Kind.NonPrivateCallableAdded ->
Errors.NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
ExpectActualMemberDiff.Kind.ReturnTypeChangedInOverride ->
Errors.RETURN_TYPE_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
ExpectActualMemberDiff.Kind.ModalityChangedInOverride ->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual typealias <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>Foo<!> = FooImpl
actual typealias Foo = FooImpl

open class FooImpl {
fun existingMethod() {}
val existingParam: Int = 904

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
actual open class Foo {
actual fun foo() {}

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
fun Int.foo() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> : Base() {
fun <T : Comparable<T>> <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(t: T) {}
actual open class Foo : Base() {
fun <T : Comparable<T>> foo(t: T) {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
actual open class Foo {
actual fun existingMethod() {}
actual val existingParam: Int = 904

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
internal fun injectedMethod() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
actual open class Foo {
actual fun existingMethod() {}
actual val existingParam: Int = 904

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
protected fun injectedMethod() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
actual open class Foo {
actual fun existingMethod() {}
actual val existingParam: Int = 904

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
fun injectedMethod() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual typealias <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>Foo<!> = FooImpl
actual typealias Foo = FooImpl

// FILE: Foo.java

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> {
actual open class Foo {
actual fun foo() {}

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
fun foo(overloaded: Int) {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt

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

actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!><R>() : Base<R>() {
fun <T> <!NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(t: T) {}
actual open class Foo<R>() : Base<R>() {
fun <T> foo(t: T) {}
}
Loading

0 comments on commit 22b9d50

Please sign in to comment.