[FIR] Enable ForbidInferringTypeVariablesIntoEmptyIntersection in 2.0

#KT-56377
This commit is contained in:
Kirill Rakhman
2023-06-20 09:49:55 +02:00
committed by Space Team
parent 585d4b3098
commit be232d3e6f
23 changed files with 23 additions and 21 deletions
@@ -29,7 +29,7 @@ fun test3() = run {
fun test4() = run {
if (p) return@run
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>incompatibleC<!>() // ? either uninferred T or error (Unit </: C)
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>incompatibleC<!>() // ? either uninferred T or error (Unit </: C)
}
fun main() {
@@ -47,7 +47,7 @@ fun test(i: Inv<Nothing>, iUnit: Inv<Unit>) {
if (iUnit is String) {
launch {
run(A.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>flexible<!>(iUnit)) { 42 }
run(A.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>flexible<!>(iUnit)) { 42 }
}
}
}
@@ -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
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING("K; B?, A?; multiple incompatible classes; : B, A")!>if (current === this) current else null<!>
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("K; B?, A?; multiple incompatible classes; : B, A")!>if (current === this) current else null<!>
}
@@ -1,6 +1,6 @@
/kt45461.kt:7:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/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<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -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
@@ -1,7 +1,7 @@
/kt45461_12.kt:7:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/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<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -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
@@ -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 <K : Int> 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<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -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
@@ -1,6 +1,6 @@
/kt45461_5.kt:7:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/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<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -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
@@ -4,7 +4,7 @@
/kt48765.kt:6:52: warning: parameter 'x2' is never used
fun <T1: Number, T2: A<Float, T1>> 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
@@ -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
@@ -5,7 +5,7 @@ fun box(): String {
return try {
val range1 = 0..1
range1 <!CAST_NEVER_SUCCEEDS!>as<!> List<Double>
range1.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>joinToString<!> { "" }
range1.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>joinToString<!> { "" }
} catch (e: java.lang.ClassCastException) {
"OK"
}
@@ -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<Int> { g() }
^
@@ -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
@@ -7,6 +7,6 @@ fun <V> genericIn(x: In<V>) {}
/selectFromCovariantAndContravariantTypes.kt:14:20: warning: parameter 'x' is never used
fun <V> genericOut(x: Out<V>) {}
^
/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))
^
@@ -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
@@ -9,7 +9,7 @@ fun <T : Foo> foo(): T? {
}
fun main() {
val a: Bar? = <!DEBUG_INFO_EXPRESSION_TYPE("Foo? & Bar?")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>foo<!>()<!>
val a: Bar? = <!DEBUG_INFO_EXPRESSION_TYPE("Foo? & Bar?")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>foo<!>()<!>
}
@@ -1,6 +1,7 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS
// !LANGUAGE: +AllowEmptyIntersectionsInResultTypeResolver
// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection
interface I
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection
class Expression<T>(val x: T)
class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>)
@@ -7,5 +7,5 @@ fun test1(l: List<Number>) {
val i: Int = l.firstTyped()
val s: String = l.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>firstTyped<!>()
val s: String = l.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>firstTyped<!>()
}
@@ -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