FE: introduce AllowEmptyIntersectionsInResultTypeResolver feature
Related to KT-51221
This commit is contained in:
committed by
Space Team
parent
fbea09b3b6
commit
47fab61716
+6
@@ -33394,6 +33394,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46186withEmptyIntersections.kt")
|
||||
public void testKt46186withEmptyIntersections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("misplacedConstraints.kt")
|
||||
public void testMisplacedConstraints() throws Exception {
|
||||
|
||||
+6
@@ -33394,6 +33394,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46186withEmptyIntersections.kt")
|
||||
public void testKt46186withEmptyIntersections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("misplacedConstraints.kt")
|
||||
public void testMisplacedConstraints() throws Exception {
|
||||
|
||||
+6
@@ -33490,6 +33490,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46186withEmptyIntersections.kt")
|
||||
public void testKt46186withEmptyIntersections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("misplacedConstraints.kt")
|
||||
public void testMisplacedConstraints() throws Exception {
|
||||
|
||||
+3
-4
@@ -265,8 +265,9 @@ class ResultTypeResolver(
|
||||
}
|
||||
|
||||
private fun Context.computeUpperType(upperConstraints: List<Constraint>): KotlinTypeMarker {
|
||||
// TODO: Remove this after stopping support of K1
|
||||
return if (!isK2) {
|
||||
return if (languageVersionSettings.supportsFeature(LanguageFeature.AllowEmptyIntersectionsInResultTypeResolver)) {
|
||||
intersectTypes(upperConstraints.map { it.type })
|
||||
} else {
|
||||
val intersectionUpperType = intersectTypes(upperConstraints.map { it.type })
|
||||
val resultIsActuallyIntersection = intersectionUpperType.typeConstructor().isIntersection()
|
||||
|
||||
@@ -291,8 +292,6 @@ class ResultTypeResolver(
|
||||
if (filteredUpperConstraints.isNotEmpty()) intersectTypes(filteredUpperConstraints) else intersectionUpperType
|
||||
} else intersectionUpperType
|
||||
upperType
|
||||
} else {
|
||||
intersectTypes(upperConstraints.map { it.type })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS
|
||||
// !LANGUAGE: -AllowEmptyIntersectionsInResultTypeResolver
|
||||
|
||||
interface I
|
||||
|
||||
@@ -9,13 +10,13 @@ abstract class View4
|
||||
interface View5
|
||||
|
||||
fun <T: View1> findViewById1(): T = null as T
|
||||
fun test1(): I = findViewById1()
|
||||
fun test1(): I = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById1()<!>
|
||||
|
||||
fun <T: View2> findViewById2(): T = null as T
|
||||
fun test2(): I = findViewById2()
|
||||
|
||||
inline fun <reified T: View1> findViewById3(): T = null as T
|
||||
fun test3(): I = findViewById3()
|
||||
fun test3(): I = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById3()<!>
|
||||
|
||||
inline fun <reified T: View2> findViewById4(): T = null as T
|
||||
fun test4(): I = findViewById4()
|
||||
@@ -39,17 +40,17 @@ inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): I = findViewById10()
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
fun test11(): View4 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById11()<!>
|
||||
|
||||
object Obj {
|
||||
fun <T: I> findViewById1(): T = null as T
|
||||
fun test1(): View1 = findViewById1()
|
||||
fun test1(): View1 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById1()<!>
|
||||
|
||||
fun <T: I> findViewById2(): T = null as T
|
||||
fun test2(): View2 = findViewById2()
|
||||
|
||||
inline fun <reified T: I> findViewById3(): T = null as T
|
||||
fun test3(): View1 = findViewById3()
|
||||
fun test3(): View1 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById3()<!>
|
||||
|
||||
inline fun <reified T: I> findViewById4(): T = null as T
|
||||
fun test4(): View2 = findViewById4()
|
||||
@@ -67,13 +68,13 @@ object Obj {
|
||||
fun test8(): View4 = findViewById8()
|
||||
|
||||
fun <T> findViewById9(): T where T: View3, T: View5 = null as T
|
||||
fun test9(): View1 = findViewById9()
|
||||
fun test9(): View1 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById9()<!>
|
||||
|
||||
inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): View1 = findViewById10()
|
||||
fun test10(): View1 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById10()<!>
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
fun test11(): View4 = <!NEW_INFERENCE_ERROR, RETURN_TYPE_MISMATCH!>findViewById11()<!>
|
||||
}
|
||||
|
||||
interface A
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS
|
||||
// !LANGUAGE: -AllowEmptyIntersectionsInResultTypeResolver
|
||||
|
||||
interface I
|
||||
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
// !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS
|
||||
// !LANGUAGE: +AllowEmptyIntersectionsInResultTypeResolver
|
||||
|
||||
interface I
|
||||
|
||||
class View1
|
||||
open class View2
|
||||
interface View3
|
||||
abstract class View4
|
||||
interface View5
|
||||
|
||||
fun <T: View1> findViewById1(): T = null as T
|
||||
fun test1(): I = findViewById1()
|
||||
|
||||
fun <T: View2> findViewById2(): T = null as T
|
||||
fun test2(): I = findViewById2()
|
||||
|
||||
inline fun <reified T: View1> findViewById3(): T = null as T
|
||||
fun test3(): I = findViewById3()
|
||||
|
||||
inline fun <reified T: View2> findViewById4(): T = null as T
|
||||
fun test4(): I = findViewById4()
|
||||
|
||||
fun <T: View3> findViewById5(): T = null as T
|
||||
fun test5(): I = findViewById5()
|
||||
|
||||
inline fun <reified T: View3> findViewById6(): T = null as T
|
||||
fun test6(): I = findViewById6()
|
||||
|
||||
fun <T: View4> findViewById7(): T = null as T
|
||||
fun test7(): I = findViewById7()
|
||||
|
||||
inline fun <reified T: View4> findViewById8(): T = null as T
|
||||
fun test8(): I = findViewById8()
|
||||
|
||||
fun <T> findViewById9(): T where T: View3, T: View5 = null as T
|
||||
fun test9(): I = findViewById9()
|
||||
|
||||
inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): I = findViewById10()
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
|
||||
object Obj {
|
||||
fun <T: I> findViewById1(): T = null as T
|
||||
fun test1(): View1 = findViewById1()
|
||||
|
||||
fun <T: I> findViewById2(): T = null as T
|
||||
fun test2(): View2 = findViewById2()
|
||||
|
||||
inline fun <reified T: I> findViewById3(): T = null as T
|
||||
fun test3(): View1 = findViewById3()
|
||||
|
||||
inline fun <reified T: I> findViewById4(): T = null as T
|
||||
fun test4(): View2 = findViewById4()
|
||||
|
||||
fun <T: I> findViewById5(): T = null as T
|
||||
fun test5(): View3 = findViewById5()
|
||||
|
||||
inline fun <reified T: I> findViewById6(): T = null as T
|
||||
fun test6(): View3 = findViewById6()
|
||||
|
||||
fun <T: I> findViewById7(): T = null as T
|
||||
fun test7(): View4 = findViewById7()
|
||||
|
||||
inline fun <reified T: I> findViewById8(): T = null as T
|
||||
fun test8(): View4 = findViewById8()
|
||||
|
||||
fun <T> findViewById9(): T where T: View3, T: View5 = null as T
|
||||
fun test9(): View1 = findViewById9()
|
||||
|
||||
inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): View1 = findViewById10()
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
}
|
||||
|
||||
interface A
|
||||
open class B {
|
||||
fun <T> f(): T where T : A, T : B = null as T
|
||||
fun g(): A = f()
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
// !DIAGNOSTICS: -FINAL_UPPER_BOUND -CAST_NEVER_SUCCEEDS
|
||||
// !LANGUAGE: +AllowEmptyIntersectionsInResultTypeResolver
|
||||
|
||||
interface I
|
||||
|
||||
class View1
|
||||
open class View2
|
||||
interface View3
|
||||
abstract class View4
|
||||
interface View5
|
||||
|
||||
fun <T: View1> findViewById1(): T = null as T
|
||||
fun test1(): I = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById1<!>()
|
||||
|
||||
fun <T: View2> findViewById2(): T = null as T
|
||||
fun test2(): I = findViewById2()
|
||||
|
||||
inline fun <reified T: View1> findViewById3(): T = null as T
|
||||
fun test3(): I = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById3<!>()
|
||||
|
||||
inline fun <reified T: View2> findViewById4(): T = null as T
|
||||
fun test4(): I = findViewById4()
|
||||
|
||||
fun <T: View3> findViewById5(): T = null as T
|
||||
fun test5(): I = findViewById5()
|
||||
|
||||
inline fun <reified T: View3> findViewById6(): T = null as T
|
||||
fun test6(): I = findViewById6()
|
||||
|
||||
fun <T: View4> findViewById7(): T = null as T
|
||||
fun test7(): I = findViewById7()
|
||||
|
||||
inline fun <reified T: View4> findViewById8(): T = null as T
|
||||
fun test8(): I = findViewById8()
|
||||
|
||||
fun <T> findViewById9(): T where T: View3, T: View5 = null as T
|
||||
fun test9(): I = findViewById9()
|
||||
|
||||
inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): I = findViewById10()
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
|
||||
object Obj {
|
||||
fun <T: I> findViewById1(): T = null as T
|
||||
fun test1(): View1 = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById1<!>()
|
||||
|
||||
fun <T: I> findViewById2(): T = null as T
|
||||
fun test2(): View2 = findViewById2()
|
||||
|
||||
inline fun <reified T: I> findViewById3(): T = null as T
|
||||
fun test3(): View1 = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById3<!>()
|
||||
|
||||
inline fun <reified T: I> findViewById4(): T = null as T
|
||||
fun test4(): View2 = findViewById4()
|
||||
|
||||
fun <T: I> findViewById5(): T = null as T
|
||||
fun test5(): View3 = findViewById5()
|
||||
|
||||
inline fun <reified T: I> findViewById6(): T = null as T
|
||||
fun test6(): View3 = findViewById6()
|
||||
|
||||
fun <T: I> findViewById7(): T = null as T
|
||||
fun test7(): View4 = findViewById7()
|
||||
|
||||
inline fun <reified T: I> findViewById8(): T = null as T
|
||||
fun test8(): View4 = findViewById8()
|
||||
|
||||
fun <T> findViewById9(): T where T: View3, T: View5 = null as T
|
||||
fun test9(): View1 = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById9<!>()
|
||||
|
||||
inline fun <reified T> findViewById10(): T where T: View3, T: View5 = null as T
|
||||
fun test10(): View1 = <!INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION!>findViewById10<!>()
|
||||
|
||||
fun <T: View2> findViewById11(): T = null as T
|
||||
fun test11(): View4 = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>findViewById11<!>()
|
||||
}
|
||||
|
||||
interface A
|
||||
open class B {
|
||||
fun <T> f(): T where T : A, T : B = null as T
|
||||
fun g(): A = f()
|
||||
}
|
||||
Generated
+6
@@ -33490,6 +33490,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46186withEmptyIntersections.kt")
|
||||
public void testKt46186withEmptyIntersections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/kt46186withEmptyIntersections.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("misplacedConstraints.kt")
|
||||
public void testMisplacedConstraints() throws Exception {
|
||||
|
||||
@@ -284,6 +284,7 @@ enum class LanguageFeature(
|
||||
// 2.0
|
||||
|
||||
EnhanceNullabilityOfPrimitiveArrays(KOTLIN_2_0, kind = BUG_FIX), // KT-54521
|
||||
AllowEmptyIntersectionsInResultTypeResolver(KOTLIN_2_0, kind = OTHER), // KT-51221
|
||||
|
||||
// End of 2.* language features --------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user