Skip to content

Commit 4408d89

Browse files
nikitabobkoSpace Team
authored and
Space Team
committed
[FE 1.0] Report a more precise diagnostic when parameter modifiers (vararg) are changed in actualization
^KT-62747 Fixed
1 parent 6982fa1 commit 4408d89

File tree

9 files changed

+62
-1
lines changed

9 files changed

+62
-1
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ public interface Errors {
859859
PROPERTY_KIND_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, VAL_OR_VAR_NODE);
860860
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
861861
LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, LATEINIT_MODIFIER);
862+
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
863+
VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, LATEINIT_MODIFIER);
862864
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
863865
TYPE_PARAMETER_NAMES_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, TYPE_PARAMETERS_OR_DECLARATION_SIGNATURE);
864866

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno
424424
MAP.put(LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING,
425425
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
426426
ExpectActualScopeDiffRenderer.INSTANCE);
427+
MAP.put(VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING,
428+
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
429+
ExpectActualScopeDiffRenderer.INSTANCE);
427430
MAP.put(SETTER_VISIBILITY_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING,
428431
"{0}. This warning will become an error in future releases. Also see https://youtrack.jetbrains.com/issue/KT-22841 for more details",
429432
ExpectActualScopeDiffRenderer.INSTANCE);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ private fun BindingTrace.reportIfPossible(diff: ExpectActualMemberDiff<CallableM
219219
Errors.PROPERTY_KIND_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
220220
ExpectActualMemberDiff.Kind.LateinitChangedInOverride ->
221221
Errors.LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
222+
ExpectActualMemberDiff.Kind.VarargChangedInOverride ->
223+
Errors.VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
222224
ExpectActualMemberDiff.Kind.TypeParameterNamesChangedInOverride ->
223225
Errors.TYPE_PARAMETER_NAMES_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
224226
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// MODULE: m1-common
2+
// FILE: common.kt
3+
4+
open class Base {
5+
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(vararg bar: Int) {}<!>
6+
}
7+
8+
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
9+
}<!>
10+
11+
// MODULE: m2-jvm()()(m1-common)
12+
// FILE: jvm.kt
13+
14+
actual open class Foo : Base() {
15+
override fun foo(bar: IntArray) {}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// MODULE: m1-common
2+
// FILE: common.kt
3+
4+
open class Base {
5+
open fun foo(vararg bar: Int) {}
6+
}
7+
8+
expect open class Foo : Base {
9+
}
10+
11+
// MODULE: m2-jvm()()(m1-common)
12+
// FILE: jvm.kt
13+
14+
actual open <!ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_MEMBERS_AS_NON_FINAL_EXPECT_CLASSIFIER_WARNING!>class Foo<!> : Base() {
15+
override fun <!VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(bar: IntArray) {}
16+
}

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.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.

core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ data class ExpectActualMemberDiff<out M, out C>(val kind: Kind, val actualMember
4545
"{0}: the property modifiers (lateinit) of this member must be the same in the expect class and the actual class. " +
4646
"This error happens because the expect class ''{1}'' is non-final"
4747
),
48+
VarargChangedInOverride(
49+
"{0}: the parameter modifiers (vararg) of this member must be the same in the expect class and the actual class. " +
50+
"This error happens because the expect class ''{1}'' is non-final"
51+
),
4852
TypeParameterNamesChangedInOverride(
4953
"{0}: the type parameter names of this member must be the same in the expect class and the actual class. " +
5054
"This error happens because the expect class ''{1}'' is non-final"
@@ -83,6 +87,6 @@ fun ExpectActualCompatibility.Incompatible<*>.toMemberDiffKind(): ExpectActualMe
8387
ExpectActualCompatibility.Incompatible.Unknown -> null // Unknown incompatibility is never reported
8488
ExpectActualCompatibility.Incompatible.ValueParameterCrossinline -> null // inline fun can't be overridden
8589
ExpectActualCompatibility.Incompatible.ValueParameterNoinline -> null // inline fun can't be overridden
86-
ExpectActualCompatibility.Incompatible.ValueParameterVararg -> ExpectActualMemberDiff.Kind.NonPrivateCallableAdded
90+
ExpectActualCompatibility.Incompatible.ValueParameterVararg -> ExpectActualMemberDiff.Kind.VarargChangedInOverride
8791
ExpectActualCompatibility.Incompatible.Visibility -> ExpectActualMemberDiff.Kind.VisibilityChangedInOverride
8892
}

0 commit comments

Comments
 (0)