[FE] Erase type parameters of super types during intersection type emptiness check as well

This commit is contained in:
Victor Petukhov
2022-04-25 12:25:06 +03:00
committed by teamcity
parent 0f1d212fc5
commit fb76d819f0
19 changed files with 106 additions and 167 deletions
@@ -15475,6 +15475,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_6.kt");
}
@Test
@TestMetadata("kt48987.kt")
public void testKt48987() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48987.kt");
}
@Test
@TestMetadata("kt49661.kt")
public void testKt49661() throws Exception {
@@ -15217,18 +15217,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("kt45461.kt")
public void testKt45461() throws Exception {
@@ -15217,18 +15217,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("kt45461.kt")
public void testKt45461() throws Exception {
@@ -12560,6 +12560,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -17571,6 +17577,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
@@ -32,7 +32,7 @@ class Test : () -> String, (Int) -> String {
fun box(): String {
var test = "Failed"
builder {
test = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>testIntersection<!>(Test())
test = testIntersection(Test())
}
if (test != "OKEmptyOK42") return "failed: $test"
@@ -36,6 +36,6 @@ object Test : () -> Unit, (Boolean) -> Unit {
}
fun box(): String {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>testIntersection<!>(Test)
testIntersection(Test)
return result
}
@@ -1,41 +0,0 @@
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: IGNORED_IN_JS
// IGNORE_BACKEND: JS, JS_IR
// IGNORE_BACKEND: JS_IR_ES6
fun interface KRunnable {
fun invoke()
}
fun interface KBoolean {
fun invoke(b: Boolean)
}
fun useFunInterface(fn: KRunnable) {
fn.invoke()
}
fun useFunInterfacePredicate(fn: KBoolean) {
fn.invoke(true)
}
fun <T> testIntersection(x: T) where T : () -> Unit, T : (Boolean) -> Unit {
useFunInterface(x)
useFunInterfacePredicate(x)
}
var result = ""
object Test : () -> Unit, (Boolean) -> Unit {
override fun invoke() {
result += "O"
}
override fun invoke(p1: Boolean) {
if (p1) result += "K"
}
}
fun box(): String {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>testIntersection<!>(Test)
return result
}
@@ -1,30 +0,0 @@
package
public var result: kotlin.String
public fun box(): kotlin.String
public fun </*0*/ T : () -> kotlin.Unit> testIntersection(/*0*/ x: T): kotlin.Unit where T : (kotlin.Boolean) -> kotlin.Unit
public fun useFunInterface(/*0*/ fn: KRunnable): kotlin.Unit
public fun useFunInterfacePredicate(/*0*/ fn: KBoolean): kotlin.Unit
public fun interface KBoolean {
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 fun invoke(/*0*/ b: kotlin.Boolean): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public fun interface KRunnable {
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 fun invoke(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object Test : () -> kotlin.Unit, (kotlin.Boolean) -> kotlin.Unit {
private constructor Test()
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun invoke(): kotlin.Unit
public open override /*1*/ fun invoke(/*0*/ p1: kotlin.Boolean): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,41 +0,0 @@
// !LANGUAGE: +SuspendConversion
// WITH_STDLIB
// WITH_COROUTINES
// IGNORE_BACKEND: JVM, NATIVE, JS, JS_IR
// IGNORE_BACKEND: JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: IGNORED_IN_JS
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun useSuspendFun(fn : suspend () -> String) = fn()
suspend fun useSuspendFunInt(fn: suspend (Int) -> String) = fn(42)
suspend fun <T> testIntersection(x: T): String where T : () -> String, T : (Int) -> String {
val a = useSuspendFun(x)
val b = useSuspendFunInt(x)
return a + b
}
class Test : () -> String, (Int) -> String {
override fun invoke(): String = "OKEmpty"
override fun invoke(p: Int) = "OK$p"
}
fun box(): String {
var test = "Failed"
builder {
test = <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>testIntersection<!>(Test())
}
if (test != "OKEmptyOK42") return "failed: $test"
return "OK"
}
@@ -1,16 +0,0 @@
package
public fun box(): kotlin.String
public fun builder(/*0*/ c: suspend () -> kotlin.Unit): kotlin.Unit
public suspend fun </*0*/ T : () -> kotlin.String> testIntersection(/*0*/ x: T): kotlin.String where T : (kotlin.Int) -> kotlin.String
public suspend fun useSuspendFun(/*0*/ fn: suspend () -> kotlin.String): kotlin.String
public suspend fun useSuspendFunInt(/*0*/ fn: suspend (kotlin.Int) -> kotlin.String): kotlin.String
public final class Test : () -> kotlin.String, (kotlin.Int) -> kotlin.String {
public constructor Test()
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun invoke(): kotlin.String
public open override /*1*/ fun invoke(/*0*/ p: kotlin.Int): kotlin.String
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -15223,18 +15223,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("kt45461.kt")
public void testKt45461() throws Exception {
@@ -12440,6 +12440,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -17145,6 +17151,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
@@ -12560,6 +12560,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -17571,6 +17577,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
@@ -10011,6 +10011,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractLightAnalysisModeTest {
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void ignoreIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@TestMetadata("onArgument.kt")
public void ignoreOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
@@ -14211,6 +14216,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
@@ -359,8 +359,13 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
// B & C can't have common subtype due to having incompatible supertypes: A<String> and A<Int>
val haveIncompatibleSupertypes = firstType.anySuperTypeConstructor { superTypeOfFirst ->
secondType.anySuperTypeConstructor { superTypeOfSecond ->
val erasedSuperTypeOfSecond by lazy { superTypeOfSecond.eraseContainingTypeParameters() }
superTypeOfFirst.typeConstructor() == superTypeOfSecond.typeConstructor()
&& !AbstractTypeChecker.equalTypes(this, superTypeOfFirst, superTypeOfSecond)
&& !AbstractTypeChecker.equalTypes(
context = this,
superTypeOfFirst.eraseContainingTypeParameters(),
erasedSuperTypeOfSecond
)
}
}
@@ -9310,6 +9310,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -13205,6 +13211,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
@@ -9352,6 +9352,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -13247,6 +13253,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
@@ -8161,6 +8161,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
@@ -11078,6 +11083,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
@@ -10248,6 +10248,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@Test
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
@@ -14257,6 +14263,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@Test
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@Test
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {