diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index cf33fb95529..e1f4354fa16 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -5556,6 +5556,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/cast/kt47685.kt"); } + @Test + @TestMetadata("kt56629.kt") + public void testKt56629() throws Exception { + runTest("compiler/testData/diagnostics/tests/cast/kt56629.kt"); + } + @Test @TestMetadata("kt614.kt") public void testKt614() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 349fe4da13b..5fc65be9445 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -5556,6 +5556,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/cast/kt47685.kt"); } + @Test + @TestMetadata("kt56629.kt") + public void testKt56629() throws Exception { + runTest("compiler/testData/diagnostics/tests/cast/kt56629.kt"); + } + @Test @TestMetadata("kt614.kt") public void testKt614() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/checkers/redundantNullCheckOnAsCast.kt b/compiler/fir/analysis-tests/testData/resolve/checkers/redundantNullCheckOnAsCast.kt index fd5819c446a..fe7df0c1bfd 100644 --- a/compiler/fir/analysis-tests/testData/resolve/checkers/redundantNullCheckOnAsCast.kt +++ b/compiler/fir/analysis-tests/testData/resolve/checkers/redundantNullCheckOnAsCast.kt @@ -2,7 +2,7 @@ fun test_1(a: Any?) { (a as String?)!! - (a as? String)!! + (a as? String)!! } fun test_2(a: Any?) { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/capturedTypeInEquality.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/capturedTypeInEquality.kt index a66bc975f82..1b2094cb29f 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/capturedTypeInEquality.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/capturedTypeInEquality.kt @@ -14,7 +14,7 @@ interface FirTarget { fun foo(target: FirTarget>, property: FirProperty) { val functionTarget = target.labeledElement - val x = (functionTarget as? FirFunction)?.let { + val x = (functionTarget as? FirFunction)?.let { if (property.getter === functionTarget) { return@let 1 } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 112a4302bdf..b3df9dc3cdf 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -5550,6 +5550,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/cast/kt47685.kt"); } + @Test + @TestMetadata("kt56629.kt") + public void testKt56629() throws Exception { + runTest("compiler/testData/diagnostics/tests/cast/kt56629.kt"); + } + @Test @TestMetadata("kt614.kt") public void testKt614() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 817f0844d7d..c5a36202dbb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -5556,6 +5556,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/cast/kt47685.kt"); } + @Test + @TestMetadata("kt56629.kt") + public void testKt56629() throws Exception { + runTest("compiler/testData/diagnostics/tests/cast/kt56629.kt"); + } + @Test @TestMetadata("kt614.kt") public void testKt614() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirCastDiagnosticsHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirCastDiagnosticsHelpers.kt index 6ae1614e146..d8103bf8033 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirCastDiagnosticsHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirCastDiagnosticsHelpers.kt @@ -8,11 +8,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.declarations.utils.isInterface -import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap import org.jetbrains.kotlin.fir.scopes.platformClassMapper -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.* @@ -254,46 +252,7 @@ fun ConeKotlinType.isNonReifiedTypeParameter(): Boolean { return this is ConeTypeParameterType && !this.lookupTag.typeParameterSymbol.isReified } -@Suppress("UNUSED_PARAMETER") -fun shouldCheckForExactType(expression: FirTypeOperatorCall, context: CheckerContext): Boolean { - return when (expression.operation) { - FirOperation.IS, FirOperation.NOT_IS -> false - // TODO, KT-59820: differentiate if this expression defines the enclosing thing's type - // e.g., - // val c1 get() = 1 as Number - // val c2: Number get() = 1 as Number - FirOperation.AS, FirOperation.SAFE_AS -> true - else -> throw AssertionError("Should not be here: ${expression.operation}") - } -} - -fun isRefinementUseless( - context: CheckerContext, - candidateType: ConeSimpleKotlinType, - targetType: ConeKotlinType, - shouldCheckForExactType: Boolean, - arg: FirExpression, -): Boolean { - return if (shouldCheckForExactType) { - if (arg is FirFunctionCall) { - val functionSymbol = arg.toResolvedCallableSymbol() as? FirFunctionSymbol<*> - if (functionSymbol != null && functionSymbol.isFunctionForExpectTypeFromCastFeature()) return false - } - - isExactTypeCast(context, candidateType, targetType) - } else { - isUpcast(context, candidateType, targetType) - } -} - -private fun isExactTypeCast(context: CheckerContext, candidateType: ConeSimpleKotlinType, targetType: ConeKotlinType): Boolean { - if (!AbstractTypeChecker.equalTypes(context.session.typeContext, candidateType, targetType, stubTypesEqualToAnything = false)) - return false - // See comments at [isUpcast] why we need to check the existence of @ExtensionFunctionType - return candidateType.isExtensionFunctionType == targetType.isExtensionFunctionType -} - -private fun isUpcast(context: CheckerContext, candidateType: ConeKotlinType, targetType: ConeKotlinType): Boolean { +fun isUpcast(context: CheckerContext, candidateType: ConeKotlinType, targetType: ConeKotlinType): Boolean { if (!AbstractTypeChecker.isSubtypeOf(context.session.typeContext, candidateType, targetType, stubTypesEqualToAnything = false)) return false diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUselessTypeOperationCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUselessTypeOperationCallChecker.kt index b86d1db725e..5183598f19c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUselessTypeOperationCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUselessTypeOperationCallChecker.kt @@ -8,35 +8,27 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext -import org.jetbrains.kotlin.fir.analysis.checkers.isRefinementUseless -import org.jetbrains.kotlin.fir.analysis.checkers.shouldCheckForExactType +import org.jetbrains.kotlin.fir.analysis.checkers.isFunctionForExpectTypeFromCastFeature +import org.jetbrains.kotlin.fir.analysis.checkers.isUpcast import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors -import org.jetbrains.kotlin.fir.expressions.FirOperation -import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall -import org.jetbrains.kotlin.fir.expressions.argument +import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.resolve.fullyExpandedType +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.types.AbstractTypeChecker -// See .../types/CastDiagnosticsUtil.kt for counterparts, including isRefinementUseless, isExactTypeCast, isUpcast. object FirUselessTypeOperationCallChecker : FirTypeOperatorCallChecker() { override fun check(expression: FirTypeOperatorCall, context: CheckerContext, reporter: DiagnosticReporter) { if (expression.operation !in FirOperation.TYPES) return val arg = expression.argument - val candidateType = arg.resolvedType.upperBoundIfFlexible().fullyExpandedType(context.session) - if (candidateType is ConeErrorType) return + val lhsType = arg.resolvedType.upperBoundIfFlexible().fullyExpandedType(context.session) + if (lhsType is ConeErrorType) return val targetType = expression.conversionTypeRef.coneType.fullyExpandedType(context.session) if (targetType is ConeErrorType) return - // x as? Type <=> x as Type? - val refinedTargetType = - if (expression.operation == FirOperation.SAFE_AS) { - targetType.withNullability(ConeNullability.NULLABLE, context.session.typeContext) - } else { - targetType - } - if (isRefinementUseless(context, candidateType, refinedTargetType, shouldCheckForExactType(expression, context), arg)) { + if (isRefinementUseless(context, lhsType, targetType, expression, arg)) { when (expression.operation) { FirOperation.IS -> reporter.reportOn(expression.source, FirErrors.USELESS_IS_CHECK, true, context) FirOperation.NOT_IS -> reporter.reportOn(expression.source, FirErrors.USELESS_IS_CHECK, false, context) @@ -49,4 +41,42 @@ object FirUselessTypeOperationCallChecker : FirTypeOperatorCallChecker() { } } } + + private fun isRefinementUseless( + context: CheckerContext, + lhsType: ConeSimpleKotlinType, + targetType: ConeKotlinType, + expression: FirTypeOperatorCall, + arg: FirExpression, + ): Boolean { + return when (expression.operation) { + FirOperation.AS, FirOperation.SAFE_AS -> { + if (arg is FirFunctionCall) { + val functionSymbol = arg.toResolvedCallableSymbol() as? FirFunctionSymbol<*> + if (functionSymbol != null && functionSymbol.isFunctionForExpectTypeFromCastFeature()) return false + } + + // Normalize `targetType` for cases like the following: + // fun f(x: Int?) { x as? Int } // USELESS_CAST is reasonable here + val refinedTargetType = + if (expression.operation == FirOperation.SAFE_AS && lhsType.isNullable) { + targetType.withNullability(ConeNullability.NULLABLE, context.session.typeContext) + } else { + targetType + } + isExactTypeCast(context, lhsType, refinedTargetType) + } + FirOperation.IS, FirOperation.NOT_IS -> { + isUpcast(context, lhsType, targetType) + } + else -> throw AssertionError("Should not be here: ${expression.operation}") + } + } + + private fun isExactTypeCast(context: CheckerContext, lhsType: ConeSimpleKotlinType, targetType: ConeKotlinType): Boolean { + if (!AbstractTypeChecker.equalTypes(context.session.typeContext, lhsType, targetType, stubTypesEqualToAnything = false)) + return false + // See comments at [isUpcast] why we need to check the existence of @ExtensionFunctionType + return lhsType.isExtensionFunctionType == targetType.isExtensionFunctionType + } } diff --git a/compiler/testData/diagnostics/tests/Casts.fir.kt b/compiler/testData/diagnostics/tests/Casts.fir.kt index 9c1a5774b9a..08399286587 100644 --- a/compiler/testData/diagnostics/tests/Casts.fir.kt +++ b/compiler/testData/diagnostics/tests/Casts.fir.kt @@ -10,8 +10,8 @@ fun test() : Unit { checkSubtype(y as Int) checkSubtype(x as Int?) checkSubtype(y as Int?) - checkSubtype(x as? Int) - checkSubtype(y as? Int) + checkSubtype(x as? Int) + checkSubtype(y as? Int) checkSubtype(x as? Int?) checkSubtype(y as? Int?) diff --git a/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt b/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt index 2e61dbfdc96..f59a2f614db 100644 --- a/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt +++ b/compiler/testData/diagnostics/tests/cast/UselessSafeCast.fir.kt @@ -15,7 +15,7 @@ fun test(x: Int?) { foo(x as? Number) if (x is Int) { - val b = x as? Int + val b = x as? Int } } diff --git a/compiler/testData/diagnostics/tests/cast/constants.fir.kt b/compiler/testData/diagnostics/tests/cast/constants.fir.kt deleted file mode 100644 index 0e33ead18e0..00000000000 --- a/compiler/testData/diagnostics/tests/cast/constants.fir.kt +++ /dev/null @@ -1,51 +0,0 @@ -fun asCall() { - 1 as Int - 1 as Byte - 1 as Short - 1 as Long - 1 as Char - 1 as Double - 1 as Float - - 1.0 as Int - 1.0 as Byte - 1.0 as Short - 1.0 as Long - 1.0 as Char - 1.0 as Double - 1.0 as Float - - 1f as Int - 1f as Byte - 1f as Short - 1f as Long - 1f as Char - 1f as Double - 1f as Float -} - -fun asSafe() { - 1 as? Int - 1 as? Byte - 1 as? Short - 1 as? Long - 1 as? Char - 1 as? Double - 1 as? Float - - 1.0 as? Int - 1.0 as? Byte - 1.0 as? Short - 1.0 as? Long - 1.0 as? Char - 1.0 as? Double - 1.0 as? Float - - 1f as? Int - 1f as? Byte - 1f as? Short - 1f as? Long - 1f as? Char - 1f as? Double - 1f as? Float -} diff --git a/compiler/testData/diagnostics/tests/cast/constants.kt b/compiler/testData/diagnostics/tests/cast/constants.kt index 66ae58f153f..c77da29ebd0 100644 --- a/compiler/testData/diagnostics/tests/cast/constants.kt +++ b/compiler/testData/diagnostics/tests/cast/constants.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun asCall() { 1 as Int 1 as Byte diff --git a/compiler/testData/diagnostics/tests/cast/kt56629.fir.kt b/compiler/testData/diagnostics/tests/cast/kt56629.fir.kt new file mode 100644 index 00000000000..b6d16574d1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/kt56629.fir.kt @@ -0,0 +1,36 @@ +// ISSUE: KT-56629, KT-56615 + +class Klass +fun foo(arg: Klass) { + arg as Klass + arg as? Klass +} + +fun test_1(a: Any?) { + (a as String?)!! + a.length + (a as? String)!! + a.length +} + +fun test_3(a: Any?) { + a as String + a as String +} + +fun test_4(a: Any?) { + a as String + a as? String +} + +fun test_5(a: Any?) { + (a as? String)!! + a.length + (a as String) +} + +fun test_6(a: Any?) { + (a as? String)!! + a.length + (a as? String) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/kt56629.kt b/compiler/testData/diagnostics/tests/cast/kt56629.kt new file mode 100644 index 00000000000..17abbce99b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/kt56629.kt @@ -0,0 +1,36 @@ +// ISSUE: KT-56629, KT-56615 + +class Klass +fun foo(arg: Klass) { + arg as Klass + arg as? Klass +} + +fun test_1(a: Any?) { + (a as String?)!! + a.length + (a as? String)!! + a.length +} + +fun test_3(a: Any?) { + a as String + a as String +} + +fun test_4(a: Any?) { + a as String + a as? String +} + +fun test_5(a: Any?) { + (a as? String)!! + a.length + (a as String) +} + +fun test_6(a: Any?) { + (a as? String)!! + a.length + (a as? String) +} diff --git a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt new file mode 100644 index 00000000000..67f14e2d02b --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.fir.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST + +fun test1(t: Any?): Any { + return t as T ?: "" +} + +fun test2(t: Any?): Any { + return t as T ?: "" +} + +fun test3(t: Any?): Any { + if (t != null) { + return t ?: "" + } + + return 1 +} + +fun takeNotNull(s: String) {} +fun notNull(): T = TODO() +fun nullable(): T? = null +fun dependOn(x: T) = x + +fun test() { + takeNotNull(notNull() ?: "") + takeNotNull(nullable() ?: "") + + val x: String? = null + takeNotNull(dependOn(x) ?: "") + takeNotNull(dependOn(dependOn(x)) ?: "") + takeNotNull(dependOn(dependOn(x as String)) ?: "") + + if (x != null) { + takeNotNull(dependOn(x) ?: "") + takeNotNull(dependOn(dependOn(x)) ?: "") + takeNotNull(dependOn(dependOn(x) as? String) ?: "") + } + + takeNotNull(bar()!!) +} + +inline fun reifiedNull(): T? = null + +fun testFrom13648() { + takeNotNull(reifiedNull() ?: "") +} + +fun bar() = unresolved \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt index 4cf20593407..2f57ac79a41 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/uselessElvis.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER, -SENSELESS_COMPARISON, -DEBUG_INFO_SMARTCAST fun test1(t: Any?): Any { diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt index 2c0f258bd37..16225859a92 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/basicOn.fir.kt @@ -13,7 +13,7 @@ fun g(a: SomeClass?) { // 'a' can be cast to SomeSubClass a.hashCode() a.foo - (a as? SomeSubClass).foo + (a as? SomeSubClass).foo (a as SomeSubClass).foo } val b = (a as? SomeSubClass)?.foo @@ -21,7 +21,7 @@ fun g(a: SomeClass?) { // 'a' can be cast to SomeSubClass a.hashCode() a.foo - (a as? SomeSubClass).foo + (a as? SomeSubClass).foo (a as SomeSubClass).foo } val c = a as? SomeSubClass @@ -29,7 +29,7 @@ fun g(a: SomeClass?) { // 'a' and 'c' can be cast to SomeSubClass a.hashCode() a.foo - (a as? SomeSubClass).foo + (a as? SomeSubClass).foo c.hashCode() c.foo } diff --git a/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt index c0c4a2e291a..f78576b1f95 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.fir.kt @@ -60,7 +60,7 @@ fun f(a: SomeClass?) { // 'c' can be cast to SomeSubClass aa.hashCode() aa.foo - (aa as? SomeSubClass).foo + (aa as? SomeSubClass).foo c.hashCode() c.foo } diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 920401760fd..fe49dea399f 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -5556,6 +5556,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/cast/kt47685.kt"); } + @Test + @TestMetadata("kt56629.kt") + public void testKt56629() throws Exception { + runTest("compiler/testData/diagnostics/tests/cast/kt56629.kt"); + } + @Test @TestMetadata("kt614.kt") public void testKt614() throws Exception { diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.1.fir.kt index fd17627d9c9..71fa34f48b9 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.1.fir.kt @@ -111,7 +111,7 @@ fun case_9(value_1: Any) { fun case_10(value_1: Collection, value_2: Collection, value_3: Collection?) { when (value_1) { value_2 as List -> {} - value_2 as? List -> {} + value_2 as? List -> {} value_3 as? MutableMap -> {} (value_2 as? Map) as MutableMap -> {} } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.2.fir.kt index f8d934e4232..92beeef9ee5 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-6/pos/5.2.fir.kt @@ -82,7 +82,7 @@ fun case_9(value_1: Any) { // TESTCASE NUMBER: 10 fun case_10(value_1: Collection, value_2: Collection, value_3: Collection?) { when (value_1) { - value_2 as List, value_2 as? List -> {} + value_2 as List, value_2 as? List -> {} value_3 as? MutableMap, (value_2 as? Map) as MutableMap -> {} } }