diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enum.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enum.kt index 4b322c5a1d9..201f15be397 100644 --- a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enum.kt +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enum.kt @@ -11,7 +11,7 @@ fun test_1(e: Enum) { val b = when (e) { Enum.A -> 1 Enum.B -> 2 - is String -> 3 + is String -> 3 } val c = when (e) { diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enumJava.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enumJava.kt index f57414dd82c..40b55a4701f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enumJava.kt +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_enumJava.kt @@ -15,7 +15,7 @@ fun test_1(e: JavaEnum) { val b = when (e) { JavaEnum.A -> 1 JavaEnum.B -> 2 - is String -> 3 + is String -> 3 }.plus(0) val c = when (e) { diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedClass.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedClass.kt index c37b08fc716..266dd7e0f86 100644 --- a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedClass.kt +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedClass.kt @@ -15,7 +15,7 @@ fun test_1(e: Base) { val b = when (e) { is Base.A -> 1 is Base.A.B -> 2 - is String -> 3 + is String -> 3 } val c = when (e) { diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/simpleIf.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/simpleIf.kt index 04653ca4545..f34efaa5680 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/simpleIf.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/simpleIf.kt @@ -17,7 +17,7 @@ fun test_2(x: Any) { fun test_3(x: Any) { when { x !is String -> {} - x !is Int -> {} + x !is Int -> {} else -> { x.length x.inc() diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/when.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/when.kt index a5e84e1accd..06d87e98e14 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/when.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures/when.kt @@ -16,7 +16,7 @@ fun test_1(x: Any?) { when { x !is A -> {} x !is B -> x.foo() - x is Int -> { + x is Int -> { x.foo() x.bar() x.inc() @@ -37,7 +37,7 @@ fun test_2(x: Any?) { when(x) { !is A -> {} !is B -> x.foo() - is Int -> { + is Int -> { x.foo() x.bar() x.inc() @@ -67,7 +67,7 @@ fun test_3(x: Any?) { x.foo() y.foo() } - is Int -> { + is Int -> { x.foo() x.bar() x.inc() diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/implicitReceivers.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/implicitReceivers.kt index b9e1fb9bd98..4251b28aeb7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/implicitReceivers.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/implicitReceivers.kt @@ -53,7 +53,7 @@ fun Any?.test_4() { foo() this.bar() bar() - } else if (this !is B) { + } else if (this !is B) { this.bar() bar() this.foo() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies/safeCall.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies/safeCall.kt index d66ff7b26a9..c728ff94e8f 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies/safeCall.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies/safeCall.kt @@ -13,7 +13,7 @@ fun test1(x: String?): Int? { @OptIn(ExperimentalContracts::class) fun test2(x: String?): Int? { contract { - returnsNotNull() implies (x is Boolean) + returnsNotNull() implies (x is Boolean) } return x?.length diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt index 8a0c2e382ad..63ab0cf0b25 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt @@ -20,7 +20,7 @@ fun deserializeAndLoadState( ) {} fun use(beforeRunTask: BeforeRunTask<*>) { - if (beforeRunTask is PersistentStateComponent<*>) { + if (beforeRunTask is PersistentStateComponent<*>) { deserializeAndLoadState(beforeRunTask) } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/unaryOperators.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/unaryOperators.kt index 0f784539789..f9932960a0f 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/unaryOperators.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/unaryOperators.kt @@ -14,5 +14,5 @@ fun foo(u: U) { val w = +i val g = "" !in u - val f = "" !is Boolean + val f = "" !is Boolean } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt index 357e2a6c0af..2a204a07336 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt @@ -46,9 +46,13 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo } private fun checkIsApplicability(l: TypeInfo, r: TypeInfo, expression: FirTypeOperatorCall, context: CheckerContext): Applicability { + val oneIsFinal = l.isFinal || r.isFinal + val oneIsNotNull = !l.type.isNullable || !r.type.isNullable + return when { isRefinementUseless(context, l.directType.upperBoundIfFlexible(), r.directType, expression) -> Applicability.USELESS_IS_CHECK isCastErased(l.directType, r.directType, context) -> Applicability.CAST_ERASED + oneIsNotNull && oneIsFinal && areUnrelated(l, r, context) -> Applicability.IMPOSSIBLE_IS_CHECK else -> Applicability.APPLICABLE } } @@ -62,13 +66,13 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo return when { isRefinementUseless(context, l.directType.upperBoundIfFlexible(), r.directType, expression) -> Applicability.USELESS_CAST l.type.isNothing && r.type.isNothingOrNullableNothing -> Applicability.APPLICABLE - r.type.isNothing -> Applicability.IMPOSSIBLE + r.type.isNothing -> Applicability.IMPOSSIBLE_CAST isNullableNothingWithNotNull -> when (expression.operation) { // (null as? WhatEver) == null FirOperation.SAFE_AS -> Applicability.USELESS_CAST - else -> Applicability.IMPOSSIBLE + else -> Applicability.IMPOSSIBLE_CAST } - oneIsNotNull && oneIsFinal && areUnrelated(l, r, context) -> Applicability.IMPOSSIBLE + oneIsNotNull && oneIsFinal && areUnrelated(l, r, context) -> Applicability.IMPOSSIBLE_CAST isCastErased(l.directType, r.directType, context) -> Applicability.CAST_ERASED else -> Applicability.APPLICABLE } @@ -91,7 +95,8 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo */ private enum class Applicability { APPLICABLE, - IMPOSSIBLE, + IMPOSSIBLE_CAST, + IMPOSSIBLE_IS_CHECK, USELESS_CAST, USELESS_IS_CHECK, CAST_ERASED, @@ -112,12 +117,15 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker(MppCheckerKind.Commo context: CheckerContext, ) { when (applicability) { - Applicability.IMPOSSIBLE -> getImpossibilityDiagnostic(l, r, context)?.let { + Applicability.IMPOSSIBLE_CAST -> getImpossibilityDiagnostic(l, r, context)?.let { reportOn(expression.source, it, context) } Applicability.USELESS_CAST -> getUselessCastDiagnostic(context)?.let { reportOn(expression.source, it, context) } + Applicability.IMPOSSIBLE_IS_CHECK -> reportOn( + expression.source, FirErrors.USELESS_IS_CHECK, expression.operation != FirOperation.IS, context, + ) Applicability.USELESS_IS_CHECK -> reportOn( expression.source, FirErrors.USELESS_IS_CHECK, expression.operation == FirOperation.IS, context, ) diff --git a/compiler/testData/diagnostics/nativeTests/forwardDeclarations.fir.kt b/compiler/testData/diagnostics/nativeTests/forwardDeclarations.fir.kt index 66bb3275ea0..dc45abfb7f7 100644 --- a/compiler/testData/diagnostics/nativeTests/forwardDeclarations.fir.kt +++ b/compiler/testData/diagnostics/nativeTests/forwardDeclarations.fir.kt @@ -68,8 +68,8 @@ fun testIs(x: Any) : Int { } } -fun testIs2(x: lib.FwdStruct) = x is cnames.structs.FwdStruct -fun testIs3(x: lib.FwdObjcClass) = x is objcnames.classes.FwdObjcClass +fun testIs2(x: lib.FwdStruct) = x is cnames.structs.FwdStruct +fun testIs3(x: lib.FwdObjcClass) = x is objcnames.classes.FwdObjcClass fun testIs4(x: lib.FwdProtocol) = x is objcnames.protocols.FwdProtocol diff --git a/compiler/testData/diagnostics/tests/IsExpressions.fir.kt b/compiler/testData/diagnostics/tests/IsExpressions.fir.kt index f6899b7253e..ebfae2dcc5c 100644 --- a/compiler/testData/diagnostics/tests/IsExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/IsExpressions.fir.kt @@ -2,7 +2,7 @@ fun test() { if (1 is Int) { - if (1 is Boolean) { + if (1 is Boolean) { } } diff --git a/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt index 418c04559bc..2840aeadd9d 100644 --- a/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt +++ b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt @@ -19,7 +19,7 @@ fun main() { System!! java.lang.System = null java.lang.System!! - System is Int + System is Int System() (System) foo@ System diff --git a/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt new file mode 100644 index 00000000000..434e79b69cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.fir.kt @@ -0,0 +1,4 @@ +class G +interface Tr + +fun f(q: Tr) = q is G<*> diff --git a/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.kt b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.kt index 09d741c8383..f53785c40c6 100644 --- a/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.kt +++ b/compiler/testData/diagnostics/tests/cast/isErasedUnrelatedAndStarred.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL class G interface Tr diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt index 2a622d446dd..d50abd76da4 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt657.fir.kt @@ -11,7 +11,7 @@ fun foo() = Pair(1, 2) -> 3 in 1..10 -> 34 4 -> 38 - is Int -> 33 + is Int -> 33 else -> 34 } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt index 4ce01aefecd..a545ef5c2a1 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt @@ -9,7 +9,7 @@ class C() { fun test(a : Any?) { if (a is B) { - if (a is C) { + if (a is C) { a.bar(); } } diff --git a/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt b/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt index e0fbbec1a88..39bfd813637 100644 --- a/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt +++ b/compiler/testData/diagnostics/tests/enum/enumSubjectTypeCheck.fir.kt @@ -30,7 +30,7 @@ fun useEn(x: En) = x fun useEn2(x: En2) = x fun bar(x: Any) { - if (x is En && x is En2) { + if (x is En && x is En2) { when (x) { En.A -> useEn(x) En2.D -> useEn2(x) diff --git a/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt b/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt index bb429822a01..8c4e05b8e4f 100644 --- a/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt @@ -5,7 +5,7 @@ interface Entity abstract class SecuredEntity(val entity: E) where E : Entity, E : SecurityCodeAware<*,*> interface SecurityCodeAware> where E : Entity, E : SecurityCodeAware fun > SecurityCodeAware.secured() : R where E : Entity, E : SecurityCodeAware = when(this) { - is Order -> SecuredOrder(this) + is Order -> SecuredOrder(this) else -> null!! } class Order : Entity diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt index 334ac63aafc..e4e4887be13 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt @@ -45,7 +45,7 @@ fun test(i: Inv, iUnit: Inv) { run { "" } } - if (iUnit is String) { + if (iUnit is String) { launch { run(A.flexible(iUnit)) { 42 } } diff --git a/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt b/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt index 2325155926e..cb207d7cd2c 100644 --- a/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt +++ b/compiler/testData/diagnostics/tests/infos/SmartCasts.fir.kt @@ -111,12 +111,12 @@ fun f13(a : A?) { c.bar() } - if (!(a is B) || !(a is C)) { + if (!(a is B) || !(a is C)) { } else { } - if (!(a is B) || !(a is C)) { + if (!(a is B) || !(a is C)) { } if (!(a is B)) return diff --git a/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt index 6038fa4c60c..dd310ef3e9a 100644 --- a/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt @@ -11,7 +11,7 @@ class C() { fun test(a : Any?) { if (a is B) { - if (a is C) { + if (a is C) { a.bar(); } } diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt new file mode 100644 index 00000000000..0458a9c6685 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.fir.kt @@ -0,0 +1,17 @@ +sealed class Sealed(val x: Int) { + object First: Sealed(12) + open class NonFirst(x: Int, val y: Int): Sealed(x) { + object Second: NonFirst(34, 2) + object Third: NonFirst(56, 3) + } + object Last: Sealed(78) +} + +fun foo(s: Sealed): Int { + return when(s) { + !is Sealed.First -> 1 + !is Sealed.Last -> 0 + // no else required + } +} + diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.kt index 68ea1da22c7..949ccc9b67c 100644 --- a/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.kt +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenNegatedTwice.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL sealed class Sealed(val x: Int) { object First: Sealed(12) open class NonFirst(x: Int, val y: Int): Sealed(x) { diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt index eed5bf1118f..f2e48e753a0 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/kt27221_irrelevantClasses.fir.kt @@ -11,7 +11,7 @@ fun foo(a: A) { if (a is B) { if (a is C) { val t = when (a) { - is CC -> "CC" + is CC -> "CC" } } } @@ -21,7 +21,7 @@ fun foo2(a: A) { if (a is C) { if (a is B) { val t = when (a) { - is CC -> "CC" + is CC -> "CC" } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/variables/aliasing.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/variables/aliasing.fir.kt index 4dfb9b15b07..31ed64dce4f 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/variables/aliasing.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/variables/aliasing.fir.kt @@ -25,7 +25,7 @@ fun test() { b.length // error c.length // OK, since `c` is aliased to `a` } - if (b is String) { + if (b is String) { a.length // error c.length // error } @@ -35,11 +35,11 @@ fun test() { } a = 2 // break `c` -> `a` - if (a is String) { + if (a is String) { b.length // error c.length // error } - if (b is String) { + if (b is String) { a.length // error c.length // error } diff --git a/compiler/testData/diagnostics/tests/visibility/kt63434.fir.kt b/compiler/testData/diagnostics/tests/visibility/kt63434.fir.kt index fd93004c938..99c2c5c5d98 100644 --- a/compiler/testData/diagnostics/tests/visibility/kt63434.fir.kt +++ b/compiler/testData/diagnostics/tests/visibility/kt63434.fir.kt @@ -11,7 +11,7 @@ fun checkCannotAccess() { object : InlineCompletionSessionManager() { fun chch() { val b: Proto = Proto() - if (b is Proto.Some) return + if (b is Proto.Some) return } } } diff --git a/compiler/testData/diagnostics/tests/when/When.fir.kt b/compiler/testData/diagnostics/tests/when/When.fir.kt index d9b6955b9bb..5fc11befa33 100644 --- a/compiler/testData/diagnostics/tests/when/When.fir.kt +++ b/compiler/testData/diagnostics/tests/when/When.fir.kt @@ -18,7 +18,7 @@ fun foo() : Int { val s = "" val x = 1 when (x) { - is String -> 1 + is String -> 1 !is Int -> 1 is Any? -> 1 is Any -> 1 diff --git a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditionsNoSubject.fir.kt b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditionsNoSubject.fir.kt index a9453ba09a4..220d5ca97fe 100644 --- a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditionsNoSubject.fir.kt +++ b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditionsNoSubject.fir.kt @@ -39,8 +39,8 @@ fun testWithSubject_ok(x: Boolean, y: Boolean?, any: Any, z: Boolean) { y ?: x -> {} x in x -> {} x !in x -> {} - x is String -> {} - x !is String -> {} + x is String -> {} + x !is String -> {} x < x -> {} x > x -> {} x <= x -> {} diff --git a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_after.fir.kt b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_after.fir.kt index 15370671f62..aec9573e03c 100644 --- a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_after.fir.kt +++ b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_after.fir.kt @@ -57,8 +57,8 @@ fun testWithSubject_bad_1(x: A) { when (x) { x in x -> {} x !in x -> {} - x is String -> {} - x !is String -> {} + x is String -> {} + x !is String -> {} x < x -> {} x > x -> {} x <= x -> {} @@ -72,8 +72,8 @@ fun testWithSubject_bad_1(x: A) { when (x) { (x in x) -> {} (x !in x) -> {} - (x is String) -> {} - (x !is String) -> {} + (x is String) -> {} + (x !is String) -> {} (x < x) -> {} (x > x) -> {} (x <= x) -> {} @@ -161,8 +161,8 @@ fun testWithRange_bad_1(x: A) { when (x) { in x in x -> {} in x !in x -> {} - in x is String -> {} - in x !is String -> {} + in x is String -> {} + in x !is String -> {} in x < x -> {} in x > x -> {} in x <= x -> {} @@ -176,8 +176,8 @@ fun testWithRange_bad_1(x: A) { when (x) { in (x in x) -> {} in (x !in x) -> {} - in (x is String) -> {} - in (x !is String) -> {} + in (x is String) -> {} + in (x !is String) -> {} in (x < x) -> {} in (x > x) -> {} in (x <= x) -> {} diff --git a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_before.fir.kt b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_before.fir.kt index 40f5a5069dc..037ca8a3ab7 100644 --- a/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_before.fir.kt +++ b/compiler/testData/diagnostics/tests/when/deprecatedSyntaxInConditions_before.fir.kt @@ -57,8 +57,8 @@ fun testWithSubject_bad_1(x: A) { when (x) { x in x -> {} x !in x -> {} - x is String -> {} - x !is String -> {} + x is String -> {} + x !is String -> {} x < x -> {} x > x -> {} x <= x -> {} @@ -72,8 +72,8 @@ fun testWithSubject_bad_1(x: A) { when (x) { (x in x) -> {} (x !in x) -> {} - (x is String) -> {} - (x !is String) -> {} + (x is String) -> {} + (x !is String) -> {} (x < x) -> {} (x > x) -> {} (x <= x) -> {} @@ -161,8 +161,8 @@ fun testWithRange_bad_1(x: A) { when (x) { in x in x -> {} in x !in x -> {} - in x is String -> {} - in x !is String -> {} + in x is String -> {} + in x !is String -> {} in x < x -> {} in x > x -> {} in x <= x -> {} @@ -176,8 +176,8 @@ fun testWithRange_bad_1(x: A) { when (x) { in (x in x) -> {} in (x !in x) -> {} - in (x is String) -> {} - in (x !is String) -> {} + in (x is String) -> {} + in (x !is String) -> {} in (x < x) -> {} in (x > x) -> {} in (x <= x) -> {} diff --git a/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessComplex.fir.kt b/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessComplex.fir.kt index 033b950e7c1..dac498d27a2 100644 --- a/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessComplex.fir.kt +++ b/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessComplex.fir.kt @@ -14,29 +14,29 @@ fun foo(a: A) { if (a !is B) return when (a) { - is A.A1 -> "" - is A.A2 -> "v" + is A.A1 -> "" + is A.A2 -> "v" }.length when (a) { - is A.A1 -> "" - is A.A2 -> "v" + is A.A1 -> "" + is A.A2 -> "v" }.length // OK when (a) { - is A.A1 -> "" - is A.A2 -> "v" - is B.B1 -> "..." // should be warning: unreachable code + is A.A1 -> "" + is A.A2 -> "v" + is B.B1 -> "..." // should be warning: unreachable code }.length // OK when (a) { - is A.A1 -> "" - is B.B1 -> "..." - is A.A2 -> "v" + is A.A1 -> "" + is B.B1 -> "..." + is A.A2 -> "v" }.length // OK when (a) { - is A.A1 -> "" - is B.B1 -> "..." + is A.A1 -> "" + is B.B1 -> "..." }.length } diff --git a/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessSimple.kt b/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessSimple.kt index c98188665e1..24418995715 100644 --- a/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessSimple.kt +++ b/compiler/testData/diagnostics/tests/when/intersectionExhaustivenessSimple.kt @@ -1,5 +1,5 @@ -// SKIP_TXT // FIR_IDENTICAL +// SKIP_TXT // !CHECK_TYPE sealed class KtClassifierSymbol diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt index a729ab6b429..68d0679513b 100644 --- a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt @@ -12,7 +12,7 @@ fun testSimpleValInWhenSubject() { fun testValWithoutInitializerWhenSubject() { when (val y: Any) { - is String -> y.length + is String -> y.length } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt index 183a2f1c329..cfd308b5800 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.fir.kt @@ -79,7 +79,7 @@ fun branchedAndNested(x: Any?, y: Any?) { fun br(y: Any?) { - if (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) { + if (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) { y.length y.inc() } @@ -90,7 +90,7 @@ fun branchedAndNestedWithNativeOperators(x: Any?, y: Any?) { equalsTrue(notEqualsNull(nullWhenNotString(x))) // x is String && ( - (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) // y is Int, String + (myAssert(y is Int) == Unit && myAssert(y is String) == Unit) // y is Int, String || equalsTrue(isInt(y) && isString(y)) // y is Int, String ) diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt index f4db9ebc50e..bd05e6f13e7 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.fir.kt @@ -45,8 +45,8 @@ fun intersectingInfo2(x: Any?, y: Any?) { // of them is absent in each arg of "||"-operator, so they *shouldn't* lead to smartcast if ((isString(x) && !notIsInt(x) && y is String) || - (!notIsString(x) && isString(y) && y is Int) || - (x is String && !notIsInt(y) && x is Int)) { + (!notIsString(x) && isString(y) && y is Int) || + (x is String && !notIsInt(y) && x is Int)) { x.length x.inc() y.length diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.2.fir.kt index dbbace2a795..dec7df0b966 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.2.fir.kt @@ -14,8 +14,8 @@ // TESTCASE NUMBER: 1 fun case_1(value_1: SealedClass) = when (value_1) { !is SealedChild1 -> {} - !is SealedChild2 -> {} - !is SealedChild3 -> {} + !is SealedChild2 -> {} + !is SealedChild3 -> {} } /* diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.4.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.4.fir.kt index f1d72961711..823b723649e 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/1.4.fir.kt @@ -18,7 +18,7 @@ fun case_1(value_1: SealedClass): String = when (value_1) { // TESTCASE NUMBER: 2 fun case_2(value_1: SealedClass) = when (value_1) { - !is SealedChild1, !is SealedChild2, !is SealedChild3 -> {} + !is SealedChild1, !is SealedChild2, !is SealedChild3 -> {} } // TESTCASE NUMBER: 3 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/9.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/9.fir.kt index 20bacf5caf8..80e1776e886 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/9.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/9.fir.kt @@ -107,7 +107,7 @@ fun case_8(value_1: Any?) { // TESTCASE NUMBER: 9 fun case_9(value_1: Any?) { - if (funWithReturnsFalse(value_1 is String) || funWithReturnsFalse(value_1 is Int)) { + if (funWithReturnsFalse(value_1 is String) || funWithReturnsFalse(value_1 is Int)) { } else { println(value_1.length) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/effects/returns/neg/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/effects/returns/neg/2.fir.kt index fc515d63326..ab8a2e4dc32 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/effects/returns/neg/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/effects/returns/neg/2.fir.kt @@ -37,7 +37,7 @@ fun T?.case_3(): Boolean { // TESTCASE NUMBER: 4 inline fun T.case_4(): Boolean { contract { - returns(null) implies (this is Int) + returns(null) implies (this is Int) } return this is Int } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt index 61fb8227e1f..dda63f78f6d 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt @@ -70,13 +70,13 @@ class case_4 : ClassLevel3() { class case_5 : ClassLevel5() { inner class case_5_1 { fun K.case_5_1_1() { - contract { returns() implies (this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this@case_5_1_1 is Float) } - if (!(this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this is Float)) throw Exception() + contract { returns() implies (this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this@case_5_1_1 is Float) } + if (!(this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this is Float)) throw Exception() } fun case_5_1_2() { - contract { returns() implies (this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null) } - if (!(this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null)) throw Exception() + contract { returns() implies (this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null) } + if (!(this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null)) throw Exception() } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/28.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/28.fir.kt index c78b6065b30..592ed45acf3 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/28.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/28.fir.kt @@ -12,7 +12,7 @@ // TESTCASE NUMBER: 1 fun > Inv.case_1() { - if (this is MutableList<*>) { + if (this is MutableList<*>) { & kotlin.collections.MutableList<*> & Inv")!>this & kotlin.collections.MutableList<*> & Inv")!>this[0] = & kotlin.collections.MutableList<*> & Inv")!>this[1] }