From 052baf1b0401473946ca21133a7b12e80f858105 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Wed, 28 Feb 2024 12:59:18 +0100 Subject: [PATCH] Revert "[FIR] Enable ForbidInferringTypeVariablesIntoEmptyIntersection in 2.0" ^KT-66196 Fixed Keep it a warning in 2.0 This reverts commit be232d3e6fa786c1630800c377d90c7cde98e3ab. --- .../tests/inference/builderInference/stubTypes/intersect.fir.kt | 2 +- .../tests/inference/coercionToUnit/afterBareReturn.fir.kt | 2 +- .../coercionToUnit/coercionToUnitWithNothingType.fir.kt | 2 +- .../emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt | 2 +- .../tests/inference/emptyIntersectionTypes/kt45461.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt45461.fir.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt | 2 +- .../inference/emptyIntersectionTypes/kt45461_12.fir.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt | 2 +- .../inference/emptyIntersectionTypes/kt45461_2.fir.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt | 2 +- .../inference/emptyIntersectionTypes/kt45461_5.fir.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt48765.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt48765.fir.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt48987.fir.kt | 2 +- .../tests/inference/emptyIntersectionTypes/kt49661.diag.txt | 2 +- .../tests/inference/emptyIntersectionTypes/kt49661.fir.diag.txt | 2 +- .../selectFromCovariantAndContravariantTypes.diag.txt | 2 +- .../selectFromCovariantAndContravariantTypes.fir.diag.txt | 2 +- .../dontIntersectUpperBoundWithExpectedType.fir.kt | 2 +- .../inference/annotationsForResolve/exactAnnotation.fir.kt | 2 +- .../src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt index a7513e9aecf..fd74d2ccce6 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt @@ -31,7 +31,7 @@ fun intersect(vararg x: In): E = null as E fun test() { val ret = build { emit("1") - intersect(getIn(), getIn()) + intersect(getIn(), getIn()) intersect(getIn(), Test.foo(getIn())) intersect(Test.foo(getIn()), Test.foo(getIn())) intersect(Test.foo(getIn()), getIn()) diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt index 6816280ac7b..d36e77a2d5b 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt @@ -29,7 +29,7 @@ fun test3() = run { fun test4() = run { if (p) return@run - incompatibleC() // ? either uninferred T or error (Unit 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/emptyIntersectionOnIf.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt index f09085f1451..97201bcfc8e 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt @@ -4,5 +4,5 @@ open class A abstract class B { fun test(current: A): A? = // K2 reports empty intersection here due to the smart cast from A to B, where A & B aren't compatible - if (current === this) current else null + if (current === this) current else null } diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt index 09c436ff6e0..ee536c7e62f 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt @@ -1,4 +1,4 @@ -/kt45461.kt:12: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 +/kt45461.kt:12: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 a future release Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 ^^^^^^^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.diag.txt index 1326d47b26c..c425fcfbf97 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.fir.diag.txt @@ -1 +1 @@ -/kt45461.kt:(245,252): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, kotlin.Int (multiple incompatible classes). This will become an error in Kotlin 2.0. +/kt45461.kt:(245,252): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, kotlin.Int (multiple incompatible classes). This will become an error in a future release. 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 cd9d7b937c6..c00f51b30dc 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,4 @@ -/kt45461_12.kt:14: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 +/kt45461_12.kt:14: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 a future release 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.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.diag.txt index ce8f1f87625..72540071376 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.fir.diag.txt @@ -1 +1 @@ -/kt45461_12.kt:(296,303): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Number). This will become an error in Kotlin 2.0. +/kt45461_12.kt:(296,303): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Number). This will become an error in a future release. 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 0b235c951cc..219210e1299 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt @@ -1,7 +1,7 @@ /kt45461_2.kt:10:10: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined fun main() { ^^^ -/kt45461_2.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, Int). This will become an error in Kotlin 2.0 +/kt45461_2.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, Int). This will become an error in a future release 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.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.diag.txt index ef8378a113e..bf6439b6d13 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.fir.diag.txt @@ -1,3 +1,3 @@ /kt45461_2.kt:(198,201): warning: Type 'kotlin.Int' is final, so the value of the type parameter is predetermined. -/kt45461_2.kt:(253,260): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Int). This will become an error in Kotlin 2.0. +/kt45461_2.kt:(253,260): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Int). This will become an error in a future release. 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 9aedfb3f4ed..3db9f2dd0dc 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt @@ -1,4 +1,4 @@ -/kt45461_5.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 +/kt45461_5.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 a future release 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.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.diag.txt index 4ed4814f2b0..c4e58295f9f 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.fir.diag.txt @@ -1 +1 @@ -/kt45461_5.kt:(269,276): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Number). This will become an error in Kotlin 2.0. +/kt45461_5.kt:(269,276): warning: Type argument for type parameter 'S' cannot be inferred because it has incompatible upper bounds: kotlin.String, K (multiple incompatible classes: kotlin/String, kotlin/Number). This will become an error in a future release. diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt index 316d4a87af8..fffdab95233 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt @@ -1,4 +1,4 @@ -/kt48765.kt:10: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 +/kt48765.kt:10: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 a future release B().foo(x, foo()) ^^^ /kt48765.kt:14:9: warning: 'String' is a final type, and thus a value of the type parameter is predetermined diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.diag.txt index 993905c8749..642138071c6 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.fir.diag.txt @@ -1,4 +1,4 @@ -/kt48765.kt:(282,285): warning: Type argument for type parameter 'T' cannot be inferred because it has incompatible upper bounds: kotlin.String, kotlin.Number (multiple incompatible classes). This will become an error in Kotlin 2.0. +/kt48765.kt:(282,285): warning: Type argument for type parameter 'T' cannot be inferred because it has incompatible upper bounds: kotlin.String, kotlin.Number (multiple incompatible classes). This will become an error in a future release. /kt48765.kt:(345,351): warning: Type 'kotlin.String' is final, so the value of the type parameter is predetermined. diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt index 86b7c4281cd..67db13724a2 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.fir.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 ec6c114ebb3..565b407d66d 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:11: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 +/kt49661.kt:11: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 a future release f { g() } ^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.diag.txt index b39adeec356..2adf5ee8da9 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.fir.diag.txt @@ -1 +1 @@ -/kt49661.fir.kt:(243,244): warning: Type argument for type parameter 'T' cannot be inferred because it has incompatible upper bounds: Foo, kotlin.Int (multiple incompatible classes). This will become an error in Kotlin 2.0. +/kt49661.fir.kt:(243,244): warning: Type argument for type parameter 'T' cannot be inferred because it has incompatible upper bounds: Foo, kotlin.Int (multiple incompatible classes). This will become an error in a future release. diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt index ad3c923f672..9b44a679ebb 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt @@ -1,4 +1,4 @@ -/selectFromCovariantAndContravariantTypes.kt:17: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 +/selectFromCovariantAndContravariantTypes.kt:17: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 a future release genericIn(select(a, b)) ^^^^^^^^^ diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.diag.txt index 4260eba6554..3c2b9e9991a 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.fir.diag.txt @@ -1 +1 @@ -/selectFromCovariantAndContravariantTypes.kt:(335,344): warning: Type argument for type parameter 'V' cannot be inferred because it has incompatible upper bounds: A, B (multiple incompatible classes). This will become an error in Kotlin 2.0. +/selectFromCovariantAndContravariantTypes.kt:(335,344): warning: Type argument for type parameter 'V' cannot be inferred because it has incompatible upper bounds: A, B (multiple incompatible classes). This will become an error in a future release. diff --git a/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt index 5989e75445e..d28b0ce367d 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt @@ -9,7 +9,7 @@ fun foo(): T? { } fun main() { - val a: Bar? = foo() + val a: Bar? = foo() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt index f80bab45e17..6c2137ae536 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt @@ -7,5 +7,5 @@ fun test1(l: List) { val i: Int = l.firstTyped() - val s: String = l.firstTyped() + val s: String = l.firstTyped() } diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index e64cb71c4a9..a92cdf42956 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -305,7 +305,6 @@ enum class LanguageFeature( SupportEffectivelyFinalInExpectActualVisibilityCheck(KOTLIN_2_0, kind = BUG_FIX), // KT-61955 ProhibitMissedMustBeInitializedWhenThereIsNoPrimaryConstructor(KOTLIN_2_0, kind = BUG_FIX), // KT-58472 MangleCallsToJavaMethodsWithValueClasses(KOTLIN_2_0, kind = OTHER), // KT-55945 - ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_2_0, kind = BUG_FIX), // KT-51221 ProhibitDefaultArgumentsInExpectActualizedByFakeOverride(KOTLIN_2_0, kind = BUG_FIX), // KT-62036 DisableCompatibilityModeForNewInference(KOTLIN_2_0, kind = OTHER), // KT-63558 (umbrella), KT-64306, KT-64307, KT-64308 DfaBooleanVariables(KOTLIN_2_0), // KT-25747 @@ -380,6 +379,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 IntrinsicConstEvaluation(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-49303 DisableCheckingChangedProgressionsResolve(sinceVersion = null, kind = OTHER), // KT-49276 ContextSensitiveEnumResolutionInWhen(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-52774