From d6f1954e71e034cc8a278500a663e5ebaf7aafa9 Mon Sep 17 00:00:00 2001 From: Victoria Petrakovich Date: Thu, 11 Jun 2026 13:43:07 +0200 Subject: [PATCH] [kotlin] KTIJ-38940 Add/fix K2_ERRORs (cherry picked from commit 1b4d68597cff30e589b2ba3e674f46c852b313f1) IJ-CR-214534 GitOrigin-RevId: 1f6ba685d5f3627e42c66c6d1a364140b0cd362b --- .../inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt | 2 +- .../safeCastWithReturn/castNeverSucceeds.kt.after | 2 +- .../movePropertyToConstructor/annotationWithUseSite.kt | 1 + .../movePropertyToConstructor/annotationWithUseSite.kt.after | 1 + .../quickfix/expressions/removeUselessIsCheckButFalse.kt | 1 + .../quickfix/expressions/removeUselessIsCheckButFalse.kt.after | 1 + .../quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt | 1 + .../expressions/removeUselessIsCheckInWhenButFalse.kt.after | 1 + .../expressions/removeUselessIsCheckInWhenMultipleConditions.kt | 1 + .../removeUselessIsCheckInWhenMultipleConditions.kt.after | 1 + .../removeUselessIsCheckInWhenMultipleConditionsFirst.kt | 1 + .../removeUselessIsCheckInWhenMultipleConditionsFirst.kt.after | 1 + .../expressions/removeUselessIsCheckInWhenNegateButTrue.kt | 1 + .../removeUselessIsCheckInWhenNegateButTrue.kt.after | 1 + .../quickfix/expressions/removeUselessIsCheckNegateButTrue.kt | 1 + .../expressions/removeUselessIsCheckNegateButTrue.kt.after | 1 + 16 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt index a4581d5a6ba8..d3dcbb8c5a20 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt +++ b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt @@ -1,5 +1,5 @@ // AFTER_ERROR: Incompatible types: String and Int -// K2_AFTER_ERROR: +// K2_AFTER_ERROR: Check for instance is always 'true'. fun test(x: Int) { x as? String //comment1 ?: return diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt.after b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt.after index 44e64b11734c..71e486859b81 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt.after +++ b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/safeCastWithReturn/castNeverSucceeds.kt.after @@ -1,5 +1,5 @@ // AFTER_ERROR: Incompatible types: String and Int -// K2_AFTER_ERROR: +// K2_AFTER_ERROR: Check for instance is always 'true'. fun test(x: Int) { if (x !is String //comment1 ) return diff --git a/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt b/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt index c5416db290a2..fc663d02d443 100644 --- a/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt +++ b/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt @@ -1,3 +1,4 @@ +// K2_AFTER_ERROR: This annotation is not repeatable. annotation class Annotation1(val a: Int = 0) annotation class Annotation2(val a: Int = 0) annotation class Annotation3(val a: Int = 0) diff --git a/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt.after b/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt.after index 6155eb144ccc..aae81421365c 100644 --- a/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt.after +++ b/plugins/kotlin/idea/tests/testData/intentions/movePropertyToConstructor/annotationWithUseSite.kt.after @@ -1,3 +1,4 @@ +// K2_AFTER_ERROR: This annotation is not repeatable. annotation class Annotation1(val a: Int = 0) annotation class Annotation2(val a: Int = 0) annotation class Annotation3(val a: Int = 0) diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt index 371bbaa5b838..8c2613e325aa 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. fun foo(a: String) { if (a is Int) { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt.after index e765d3abf040..a2300d69a526 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckButFalse.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. fun foo(a: String) { if (false) { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt index 643075d7ba3a..17d0b4a84d61 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. interface Base interface Derived: Base diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt.after index abe9fa10dfc1..0a41b73bf1c1 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenButFalse.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. interface Base interface Derived: Base diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt index c2e5999a928c..222b85b994d5 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. open class A class B: A() class C: A() diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt.after index ac18314c8540..11da529003f0 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditions.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. open class A class B: A() class C: A() diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt index 37c9bef4f7e5..38b21f16c981 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. open class A class B: A() class C: A() diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt.after index ac18314c8540..11da529003f0 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenMultipleConditionsFirst.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'false'. open class A class B: A() class C: A() diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt index 94a55e9fb58d..6c9e86eda5ba 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'true'. interface Base interface Derived: Base diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt.after index 3b168b758c3b..06f1a383708f 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckInWhenNegateButTrue.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'true'. interface Base interface Derived: Base diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt index f590ee601a1b..53b2f571e3df 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'true'. fun foo(a: String) { if (a !is Int) { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt.after index e01a12fcef1e..bdd358b6cc0d 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/expressions/removeUselessIsCheckNegateButTrue.kt.after @@ -1,4 +1,5 @@ // "Remove redundant 'is' check" "true" +// K2_ERROR: Check for instance is always 'true'. fun foo(a: String) { if (true) {