From 40cf415fd6120d0ae56236a1e9999d61242787d5 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Thu, 19 Oct 2023 16:04:27 +0200 Subject: [PATCH] [FE 1.0] Refactoring: replace defensive NonPrivateCallableAdded with Unknown Motivation: I'm going to drop NonPrivateCallableAdded (KT-62655) in the next commits. But I don't want to change the existing logic when I drop it. That's why I have to introduce the "Unknown" case --- .../src/org/jetbrains/kotlin/diagnostics/Errors.java | 2 ++ .../diagnostics/rendering/DefaultErrorMessages.java | 3 +++ ...tHasTheSameMembersAsNonFinalExpectClassifierChecker.kt | 8 +++++--- .../resolve/multiplatform/ExpectActualMemberDiff.kt | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 5a2deaff5b78e..a331bb1d17ef4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -845,6 +845,8 @@ public interface Errors { DiagnosticFactory3.create(WARNING, DECLARATION_NAME); DiagnosticFactory1> NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); + DiagnosticFactory1> + UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); DiagnosticFactory1> RETURN_TYPE_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING = DiagnosticFactory1.create(WARNING, DECLARATION_RETURN_TYPE); DiagnosticFactory1> diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index ce42e671dec51..82633b3a69a88 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -406,6 +406,9 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno 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); MAP.put(RETURN_TYPE_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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker.kt index a8cafa74dcc12..5bb267ff12d14 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker.kt @@ -171,9 +171,9 @@ private fun calculateExpectActualScopeDiff( // 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. // Those broken invariants just needs to be reported by other checkers. - // But it's better to report some error (ExpectActualMemberDiff.Kind.NonPrivateCallableAdded in our case) to - // make sure that we don't have missed compilation errors if the invariants change - ?: ExpectActualMemberDiff.Kind.NonPrivateCallableAdded + // But it's better to report ExpectActualMemberDiff.Kind.Unknown to make sure that we don't have missed + // compilation errors if the invariants change + ?: ExpectActualMemberDiff.Kind.Unknown } } } @@ -223,6 +223,8 @@ private fun BindingTrace.reportIfPossible(diff: ExpectActualMemberDiff Errors.TYPE_PARAMETER_NAMES_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff) + ExpectActualMemberDiff.Kind.Unknown -> + Errors.UNKNOWN_PROBLEM_DURING_NON_FINAL_CLASSIFIER_ACTUALIZATION_WARNING.on(psi, diff) } report(diagnostic) } diff --git a/core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt b/core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt index 14129f75a481e..e4324bb3a5d56 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt @@ -53,6 +53,10 @@ data class ExpectActualMemberDiff(val kind: Kind, val actualMember "{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" ), + Unknown( + "{0}: normally, this error should never happen. Please report to https://kotl.in/issue. " + + "This error happens because the expect class ''{1}'' is non-final" + ) } }