From be232d3e6fa786c1630800c377d90c7cde98e3ab Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 20 Jun 2023 09:49:55 +0200 Subject: [PATCH] [FIR] Enable ForbidInferringTypeVariablesIntoEmptyIntersection in 2.0 #KT-56377 --- .../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 +- .../tests/typeParameters/kt46186withEmptyIntersections.kt | 1 + compiler/testData/diagnostics/testsWithStdLib/greater.kt | 1 + .../inference/annotationsForResolve/exactAnnotation.fir.kt | 2 +- .../src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt | 2 +- 23 files changed, 23 insertions(+), 21 deletions(-) diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt index d36e77a2d5b..6816280ac7b 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 97201bcfc8e..f09085f1451 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 729804abb53..eaa9979ed21 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.diag.txt @@ -1,6 +1,6 @@ /kt45461.kt:7:25: warning: parameter 'foo' is never used fun takeFoo(foo: Foo) {} ^ -/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 +/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 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 b9140e0e2f8..3af7c2e6769 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 a type parameter S can't be inferred because it has incompatible upper bounds: kotlin/String, kotlin/Int (multiple incompatible classes). This will become an error in a future release +/kt45461.kt:(245,252): warning: Type argument for a type parameter S can't be inferred because it has incompatible upper bounds: kotlin/String, kotlin/Int (multiple incompatible classes). This will become an error in Kotlin 2.0 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 cfac0a7694a..be373608aee 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.diag.txt @@ -1,7 +1,7 @@ /kt45461_12.kt:7:25: warning: parameter 'foo' is never used fun takeFoo(foo: Foo) {} ^ -/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 +/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 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 1711be912a1..72aed51a0c8 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 a type parameter S can't 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 +/kt45461_12.kt:(296,303): warning: Type argument for a type parameter S can't 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 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 3554a735a5f..9c711b1ba6f 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.diag.txt @@ -4,7 +4,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 a future release +/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 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 15a8f326c07..d69d527d868 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: 'kotlin/Int' is a final type, and thus a value of the type parameter is predetermined -/kt45461_2.kt:(253,260): warning: Type argument for a type parameter S can't 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 +/kt45461_2.kt:(253,260): warning: Type argument for a type parameter S can't 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 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 4d4f97a0257..ac1958b7595 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.diag.txt @@ -1,6 +1,6 @@ /kt45461_5.kt:7:25: warning: parameter 'foo' is never used fun takeFoo(foo: Foo) {} ^ -/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 +/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 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 b17b7f65bd8..ec2084ef695 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 a type parameter S can't 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 +/kt45461_5.kt:(269,276): warning: Type argument for a type parameter S can't 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 diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt index 6f5333c4718..efa3c21c3c8 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.diag.txt @@ -4,7 +4,7 @@ /kt48765.kt:6:52: warning: parameter 'x2' is never used fun > foo(x1: T2, x2: T1) {} ^ -/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 +/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 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 c85d29a1d39..b382dcafe09 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 a type parameter T can't 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:(282,285): warning: Type argument for a type parameter T can't 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:(345,351): warning: 'kotlin/String' is a final type, and thus a 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 67db13724a2..86b7c4281cd 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 ae2953de3d0..ec6c114ebb3 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:12: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 +/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 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 8acc734cf39..2f97c102422 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.kt:(251,252): warning: Type argument for a type parameter T can't be inferred because it has incompatible upper bounds: Foo, kotlin/Int (multiple incompatible classes). This will become an error in a future release +/kt49661.fir.kt:(243,244): warning: Type argument for a type parameter T can't be inferred because it has incompatible upper bounds: Foo, kotlin/Int (multiple incompatible classes). This will become an error in Kotlin 2.0 diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt index d5886631e43..cc3f151eca0 100644 --- a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.diag.txt @@ -7,6 +7,6 @@ fun genericIn(x: In) {} /selectFromCovariantAndContravariantTypes.kt:14:20: warning: parameter 'x' is never used fun genericOut(x: Out) {} ^ -/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 +/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 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 1f76e86a5af..610cfa0fb0a 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 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 +/selectFromCovariantAndContravariantTypes.kt:(335,344): 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 diff --git a/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/dontIntersectUpperBoundWithExpectedType.fir.kt index d28b0ce367d..5989e75445e 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/tests/typeParameters/kt46186withEmptyIntersections.kt b/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt index 9e18f1fd557..a8fd881e9bd 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt @@ -1,6 +1,7 @@ // FIR_IDENTICAL // !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS // !LANGUAGE: +AllowEmptyIntersectionsInResultTypeResolver +// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection interface I diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.kt index e6357112d44..5ee017e0692 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.kt @@ -1,4 +1,5 @@ // FIR_IDENTICAL +// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection class Expression(val x: T) class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/exactAnnotation.fir.kt index 99f51a0a3f8..4ab5791bab0 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 ea88077c78b..f82e1b29b9c 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -292,6 +292,7 @@ enum class LanguageFeature( ProhibitOpenValDeferredInitialization(KOTLIN_2_0, kind = BUG_FIX), // KT-57553 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 // 2.1 @@ -347,7 +348,6 @@ 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