diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index b19ea5d7916..dad5ff47f5a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -35562,6 +35562,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/when/TopLevelSealed.kt"); } + @Test + @TestMetadata("TypeParameterError.kt") + public void testTypeParameterError() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterError.kt"); + } + + @Test + @TestMetadata("TypeParameterWarning.kt") + public void testTypeParameterWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt"); + } + @Test @TestMetadata("When.kt") public void testWhen() throws Exception { 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 fbd133b61ca..18e82c7dac9 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 @@ -35562,6 +35562,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/when/TopLevelSealed.kt"); } + @Test + @TestMetadata("TypeParameterError.kt") + public void testTypeParameterError() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterError.kt"); + } + + @Test + @TestMetadata("TypeParameterWarning.kt") + public void testTypeParameterWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt"); + } + @Test @TestMetadata("When.kt") public void testWhen() 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 8f9a360601f..f57a9f64f26 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 @@ -35658,6 +35658,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/when/TopLevelSealed.kt"); } + @Test + @TestMetadata("TypeParameterError.kt") + public void testTypeParameterError() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterError.kt"); + } + + @Test + @TestMetadata("TypeParameterWarning.kt") + public void testTypeParameterWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt"); + } + @Test @TestMetadata("When.kt") public void testWhen() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt index a7534a4991e..70a0c2fb361 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt @@ -27,7 +27,7 @@ fun test3() = run incompatibleI() // ? either uninferred T or error (Unit run { +fun test4() = run { if (p) return@run incompatibleC() // ? either uninferred T or error (Unit , iUnit: Inv) { if (iUnit is String) { launch { - run(A.flexible(iUnit)) { 42 } + run(A.flexible(iUnit)) { 42 } } } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt index ad5b187684e..c266cfd2735 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt @@ -20,7 +20,7 @@ object OnlyOne { fun , S : T> greater(x: Bar, t: T) {} fun test(b: Bar) { - greater(b, b) + greater(b, b) } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt index 3e124976496..0149bc95630 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt @@ -1,3 +1,6 @@ -/kt45461.kt:10:19: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, Int (multiple incompatible classes) +/kt45461.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461.kt:10:19: warning: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, Int (multiple incompatible classes). This will become an error in Kotlin 2.0 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt index bf6039f5b4c..e40831994e8 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt @@ -7,5 +7,5 @@ class Bar { fun main() { val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt index 73342d7bf1c..d425bda2019 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt @@ -1,4 +1,7 @@ -/kt45461_12.kt:12:19: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Number) +/kt45461_12.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_12.kt:12:19: warning: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Number). This will become an error in Kotlin 2.0 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt index 4024aa17b80..7dad9ad84c1 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt @@ -9,5 +9,5 @@ interface A fun main() where N: A, N: Number { val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt index 606c50ada14..9bd644656b5 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt @@ -1,4 +1,10 @@ -/kt45461_2.kt:10:19: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Int) +/kt45461_2.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_2.kt:8:10: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined +fun main() { + ^ +/kt45461_2.kt:10:19: warning: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Int). This will become an error in Kotlin 2.0 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt index efca16742f4..2781cfc959b 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt @@ -7,5 +7,5 @@ class Bar { fun Int> main() { val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt index 6971be474d7..aa45a301ae9 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt @@ -1,3 +1,6 @@ -/kt45461_5.kt:10:19: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Number) +/kt45461_5.kt:5:25: warning: parameter 'foo' is never used + fun takeFoo(foo: Foo) {} + ^ +/kt45461_5.kt:10:19: warning: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Number). This will become an error in Kotlin 2.0 Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt index ddb67e48792..cc208e86568 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt @@ -7,5 +7,5 @@ class Bar { fun main() { val foo = Foo() - Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt index 6208d961335..e496cf130b9 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt @@ -1,4 +1,16 @@ -/kt48765.kt:8:13: error: type argument for a type parameter T can't be inferred because it has incompatible upper bounds: String, Number (multiple incompatible classes) +/kt48765.kt:4:44: warning: parameter 'x1' is never used + fun > foo(x1: T2, x2: T1) {} + ^ +/kt48765.kt:4:52: warning: parameter 'x2' is never used + fun > foo(x1: T2, x2: T1) {} + ^ +/kt48765.kt:8:13: warning: type argument for a type parameter T can't be inferred because it has incompatible upper bounds: String, Number (multiple incompatible classes). This will become an error in Kotlin 2.0 B().foo(x, foo()) ^ +/kt48765.kt:12:9: warning: 'String' is a final type, and thus a value of the type parameter is predetermined +fun foo(): T { + ^ +/kt48765.kt:13:15: warning: unchecked cast: String to T + return "" as T // this cast is safe because String is final. + ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt index e4c89a6ca8d..05acaf924fd 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt @@ -5,7 +5,7 @@ class B { } class C(val x: T, val y: T2) { fun test() { - B().foo(x, foo()) + B().foo(x, foo()) } } open class D: A() diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt index ef4fcd6b323..4359b1fbd96 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt @@ -7,5 +7,5 @@ fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { fun main() { val func: (DoesNotImplementBase) -> Unit = { } - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt index f7571d72f1c..bac2fc1c8c6 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt @@ -7,5 +7,5 @@ fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { fun main() { val func: (DoesNotImplementBase) -> Unit = { } - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.kt index bdb76425f31..c6e2f84b3da 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.kt @@ -5,7 +5,7 @@ fun box(): String { return try { val range1 = 0..1 range1 as List - range1.joinToString { "" } + range1.joinToString { "" } } catch (e: java.lang.ClassCastException) { "OK" } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.diag.txt index 66d72082bb0..e94577ed23e 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.diag.txt @@ -1,4 +1,4 @@ -/kt49661.kt:10:5: error: type argument for a type parameter T can't be inferred because it has incompatible upper bounds: Foo, Int (multiple incompatible classes) +/kt49661.kt:10:5: warning: type argument for a type parameter T can't be inferred because it has incompatible upper bounds: Foo, Int (multiple incompatible classes). This will become an error in Kotlin 2.0 f { g() } ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt index 4aab25847d8..82797f0de8b 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt @@ -7,5 +7,5 @@ inline fun f(block: ()->R?): R? { } fun main() { - f { g() } + f { g() } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52393.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52393.kt index 61ebeafe37f..4555648b2f5 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52393.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52393.kt @@ -12,6 +12,6 @@ fun main() { // val number: Long = 5 // works with (WrapperFunctions()) { - wrapper greaterEq number + wrapper greaterEq number } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52431.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52431.kt index 15d5eca1ed5..99e05da1c82 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52431.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt52431.kt @@ -9,5 +9,5 @@ infix fun , S : T?> ExpressionWithColumnType.less(t: T) infix fun , S : T?> Expression.less(other: Expression) {} fun main(x: Column, y: Double) { - x less y // error in 1.7.20, no error in 1.7.0 + x less y // error in 1.7.20, no error in 1.7.0 } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt index e799b8183b2..649762a83c0 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt @@ -3,5 +3,5 @@ fun String> g(): T? = null fun f(block: () -> R?): R? = block() fun main() { - f { g() /* OK, g() is inferred into {Int & String}? */ } + f { g() /* OK, g() is inferred into {Int & String}? */ } } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt index 950ca0ac77a..700e3a4d65d 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt @@ -1,3 +1,12 @@ -/selectFromCovariantAndContravariantTypes.kt:15:5: error: type argument for a type parameter V can't be inferred because it has incompatible upper bounds: A, B (multiple incompatible classes) +/selectFromCovariantAndContravariantTypes.kt:10:22: warning: parameter 'y' is never used +fun select(x: K, y: K): K = x + ^ +/selectFromCovariantAndContravariantTypes.kt:11:19: warning: parameter 'x' is never used +fun genericIn(x: In) {} + ^ +/selectFromCovariantAndContravariantTypes.kt:12:20: warning: parameter 'x' is never used +fun genericOut(x: Out) {} + ^ +/selectFromCovariantAndContravariantTypes.kt:15:5: warning: type argument for a type parameter V can't be inferred because it has incompatible upper bounds: A, B (multiple incompatible classes). This will become an error in Kotlin 2.0 genericIn(select(a, b)) ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt index 69cad64465e..3be8a519d2d 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt @@ -12,7 +12,7 @@ fun genericIn(x: In) {} fun genericOut(x: Out) {} fun test1(a: In, b: In) { - genericIn(select(a, b)) + genericIn(select(a, b)) } fun test2(a: Out, b: Out) { diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt b/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt new file mode 100644 index 00000000000..adcf2aa8801 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TypeParameterError.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +// FILE: ObjectNode.java + +public interface ObjectNode { + T set(String fieldName, JsonNode value); +} + +// FILE: JsonNode.java + +public class JsonNode + +// FILE: test.kt + +interface JsonObject +class SomeJsonObject() : JsonObject + +fun String.put(value: JsonObject?, node: ObjectNode) { + when (value) { + null -> node.set(this, null) + is SomeJsonObject -> Unit + else -> TODO() + } +} + +fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterError.kt b/compiler/testData/diagnostics/tests/when/TypeParameterError.kt new file mode 100644 index 00000000000..126aad27323 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TypeParameterError.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection +// FILE: ObjectNode.java + +public interface ObjectNode { + T set(String fieldName, JsonNode value); +} + +// FILE: JsonNode.java + +public class JsonNode + +// FILE: test.kt + +interface JsonObject +class SomeJsonObject() : JsonObject + +fun String.put(value: JsonObject?, node: ObjectNode) { + when (value) { + null -> node.set(this, null) + is SomeJsonObject -> Unit + else -> TODO() + } +} + +fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterError.txt b/compiler/testData/diagnostics/tests/when/TypeParameterError.txt new file mode 100644 index 00000000000..57d76732e0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TypeParameterError.txt @@ -0,0 +1,32 @@ +package + +public fun TODO(): kotlin.Nothing +public fun kotlin.String.put(/*0*/ value: JsonObject?, /*1*/ node: ObjectNode): kotlin.Unit + +public open class JsonNode { + public constructor JsonNode() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface JsonObject { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ObjectNode { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract operator fun set(/*0*/ fieldName: kotlin.String!, /*1*/ value: JsonNode!): T! + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class SomeJsonObject : JsonObject { + public constructor SomeJsonObject() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt new file mode 100644 index 00000000000..a9dc0dc2207 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.fir.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection +// FILE: ObjectNode.java + +public interface ObjectNode { + T set(String fieldName, JsonNode value); +} + +// FILE: JsonNode.java + +public class JsonNode + +// FILE: test.kt + +interface JsonObject +class SomeJsonObject() : JsonObject + +fun String.put(value: JsonObject?, node: ObjectNode) { + when (value) { + null -> node.set(this, null) + is SomeJsonObject -> Unit + else -> TODO() + } +} + +fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt new file mode 100644 index 00000000000..b5923e83e86 --- /dev/null +++ b/compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection +// FILE: ObjectNode.java + +public interface ObjectNode { + T set(String fieldName, JsonNode value); +} + +// FILE: JsonNode.java + +public class JsonNode + +// FILE: test.kt + +interface JsonObject +class SomeJsonObject() : JsonObject + +fun String.put(value: JsonObject?, node: ObjectNode) { + when (value) { + null -> node.set(this, null) + is SomeJsonObject -> Unit + else -> TODO() + } +} + +fun TODO(): Nothing = null!! diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.kt index ac5ce22a56d..a5e1b0a7e61 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.kt @@ -7,6 +7,6 @@ fun , S : T?> Expression.greater(other: T): GreaterOp = fun foo(countExpr: Expression) { countExpr.greater(0) - countExpr.greater("0") + countExpr.greater("0") countExpr.greater("0") } 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 2521b62f629..0924959ee55 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 @@ -35658,6 +35658,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/when/TopLevelSealed.kt"); } + @Test + @TestMetadata("TypeParameterError.kt") + public void testTypeParameterError() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterError.kt"); + } + + @Test + @TestMetadata("TypeParameterWarning.kt") + public void testTypeParameterWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/when/TypeParameterWarning.kt"); + } + @Test @TestMetadata("When.kt") public void testWhen() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 250a980b5db..98ddea28b21 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -265,7 +265,6 @@ enum class LanguageFeature( StopPropagatingDeprecationThroughOverrides(KOTLIN_1_9, kind = BUG_FIX), // KT-47902 ReportTypeVarianceConflictOnQualifierArguments(KOTLIN_1_9, kind = BUG_FIX), // KT-50947 ReportErrorsOnRecursiveTypeInsidePlusAssignment(KOTLIN_1_9, kind = BUG_FIX), // KT-48546 - ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_9, kind = BUG_FIX), // KT-51221 ForbidExtensionCallsOnInlineFunctionalParameters(KOTLIN_1_9, kind = BUG_FIX), // KT-52502 ForbidInferringPostponedTypeVariableIntoDeclaredUpperBound(KOTLIN_1_9, kind = BUG_FIX), // KT-47986 KeepNullabilityWhenApproximatingLocalType(KOTLIN_1_9, kind = BUG_FIX), // KT-53982 @@ -328,6 +327,7 @@ enum class LanguageFeature( EnableDfaWarningsInK2(sinceVersion = null, kind = OTHER), // KT-50965 ContractSyntaxV2(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-56127 ImplicitSignedToUnsignedIntegerConversion(sinceVersion = null), // KT-56583 + ForbidInferringTypeVariablesIntoEmptyIntersection(sinceVersion = null, kind = BUG_FIX), // KT-51221 ; init {