Skip to content

Commit

Permalink
[FE 1.0] Report a more precise diagnostic when parameter modifiers (v…
Browse files Browse the repository at this point in the history
…ararg) are changed in actualization

^KT-62747 Fixed
  • Loading branch information
nikitabobko authored and qodana-bot committed Oct 20, 2023
1 parent 6982fa1 commit 4408d89
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 1 deletion.

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 @@ -859,6 +859,8 @@ public interface Errors {
PROPERTY_KIND_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, VAL_OR_VAR_NODE);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, LATEINIT_MODIFIER);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, LATEINIT_MODIFIER);
DiagnosticFactory1<KtCallableDeclaration, ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>>
TYPE_PARAMETER_NAMES_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, TYPE_PARAMETERS_OR_DECLARATION_SIGNATURE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno
MAP.put(LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_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(VARARG_CHANGED_IN_NON_FINAL_EXPECT_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(SETTER_VISIBILITY_CHANGED_IN_NON_FINAL_EXPECT_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 @@ -219,6 +219,8 @@ private fun BindingTrace.reportIfPossible(diff: ExpectActualMemberDiff<CallableM
Errors.PROPERTY_KIND_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
ExpectActualMemberDiff.Kind.LateinitChangedInOverride ->
Errors.LATEINIT_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
ExpectActualMemberDiff.Kind.VarargChangedInOverride ->
Errors.VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
ExpectActualMemberDiff.Kind.TypeParameterNamesChangedInOverride ->
Errors.TYPE_PARAMETER_NAMES_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// MODULE: m1-common
// FILE: common.kt

open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(vararg bar: Int) {}<!>
}

<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
}<!>

// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt

actual open class Foo : Base() {
override fun foo(bar: IntArray) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// MODULE: m1-common
// FILE: common.kt

open class Base {
open fun foo(vararg bar: Int) {}
}

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() {
override fun <!VARARG_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING!>foo<!>(bar: IntArray) {}
}

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 @@ -45,6 +45,10 @@ data class ExpectActualMemberDiff<out M, out C>(val kind: Kind, val actualMember
"{0}: the property modifiers (lateinit) of this member must be the same in the expect class and the actual class. " +
"This error happens because the expect class ''{1}'' is non-final"
),
VarargChangedInOverride(
"{0}: the parameter modifiers (vararg) of this member must be the same in the expect class and the actual class. " +
"This error happens because the expect class ''{1}'' is non-final"
),
TypeParameterNamesChangedInOverride(
"{0}: the type parameter names of this member must be the same in the expect class and the actual class. " +
"This error happens because the expect class ''{1}'' is non-final"
Expand Down Expand Up @@ -83,6 +87,6 @@ fun ExpectActualCompatibility.Incompatible<*>.toMemberDiffKind(): ExpectActualMe
ExpectActualCompatibility.Incompatible.Unknown -> null // Unknown incompatibility is never reported
ExpectActualCompatibility.Incompatible.ValueParameterCrossinline -> null // inline fun can't be overridden
ExpectActualCompatibility.Incompatible.ValueParameterNoinline -> null // inline fun can't be overridden
ExpectActualCompatibility.Incompatible.ValueParameterVararg -> ExpectActualMemberDiff.Kind.NonPrivateCallableAdded
ExpectActualCompatibility.Incompatible.ValueParameterVararg -> ExpectActualMemberDiff.Kind.VarargChangedInOverride
ExpectActualCompatibility.Incompatible.Visibility -> ExpectActualMemberDiff.Kind.VisibilityChangedInOverride
}

0 comments on commit 4408d89

Please sign in to comment.