[Test] KT-59012: tests for inferring types based on self upper bound
Add tests on JK inheritance cases, extension functions for Enum and some basic recursive type cases
This commit is contained in:
committed by
Space Team
parent
e1df52bc02
commit
14b6f6d050
+18
@@ -19771,12 +19771,30 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumExtensionFunction.kt")
|
||||
public void testEnumExtensionFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/enumExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overridingJKCases.kt")
|
||||
public void testOverridingJKCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/overridingJKCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereAndWithCases.kt")
|
||||
public void testWhereAndWithCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/whereAndWithCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
|
||||
+18
@@ -19771,12 +19771,30 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumExtensionFunction.kt")
|
||||
public void testEnumExtensionFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/enumExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overridingJKCases.kt")
|
||||
public void testOverridingJKCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/overridingJKCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereAndWithCases.kt")
|
||||
public void testWhereAndWithCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/whereAndWithCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
|
||||
+18
@@ -19765,12 +19765,30 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumExtensionFunction.kt")
|
||||
public void testEnumExtensionFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/enumExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overridingJKCases.kt")
|
||||
public void testOverridingJKCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/overridingJKCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereAndWithCases.kt")
|
||||
public void testWhereAndWithCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/whereAndWithCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
|
||||
+18
@@ -19771,12 +19771,30 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumExtensionFunction.kt")
|
||||
public void testEnumExtensionFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/enumExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overridingJKCases.kt")
|
||||
public void testOverridingJKCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/overridingJKCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereAndWithCases.kt")
|
||||
public void testWhereAndWithCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/whereAndWithCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun <G : Enum<G>, T : G> Enum<G>.foo(): T = TODO()
|
||||
fun <G : Enum<G>, T : G> Enum<G>.bar(vararg args: T): Unit = TODO()
|
||||
|
||||
fun <G : Enum<G>> enumTest(a: Enum<G>) {
|
||||
val x = <!DEBUG_INFO_EXPRESSION_TYPE("G")!>a.foo()<!>
|
||||
x
|
||||
a.bar()
|
||||
}
|
||||
|
||||
fun enumStarTest(a: Enum<*>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("CapturedType(*)")!>a.foo()<!>
|
||||
a.bar()
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun <G : Enum<G>, T : G> Enum<G>.foo(): T = TODO()
|
||||
fun <G : Enum<G>, T : G> Enum<G>.bar(vararg args: T): Unit = TODO()
|
||||
|
||||
fun <G : Enum<G>> enumTest(a: Enum<G>) {
|
||||
val x = <!DEBUG_INFO_EXPRESSION_TYPE("G")!>a.foo()<!>
|
||||
x
|
||||
a.bar()
|
||||
}
|
||||
|
||||
fun enumStarTest(a: Enum<*>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>a.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>foo<!>()<!>
|
||||
<!UNREACHABLE_CODE!>a.bar()<!>
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
// FILE: I.java
|
||||
public interface I<G extends I<G>> {
|
||||
<T extends G> T foo();
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public class J<G extends J<G>> {
|
||||
<T extends G> void foo(T...args) {}
|
||||
}
|
||||
|
||||
// FILE: Main.kt
|
||||
class A1<G: A1<G>> : I<G> {
|
||||
override fun <T : G> foo(): T = TODO()
|
||||
}
|
||||
|
||||
class B1<G: I<G>> : I<G> {
|
||||
override fun <T : G> foo(): T = TODO()
|
||||
}
|
||||
|
||||
abstract class C1<G: I<G>> : I<G>
|
||||
|
||||
class A2<G: A2<G>> : J<G>() {}
|
||||
|
||||
class B2<G: J<G>> : J<G>() {}
|
||||
|
||||
class C2<G: C2<G>> : J<G>() {
|
||||
public override fun <T : G> foo(vararg args: T) {}
|
||||
}
|
||||
|
||||
class D2<G: J<G>> : J<G>() {
|
||||
public override fun <T : G> foo(vararg args: T) {}
|
||||
}
|
||||
|
||||
fun javaInterfaceTest(a: A1<*>, b: B1<*>, c: C1<*>) {
|
||||
val x = a.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("A1<*>")!>x<!>
|
||||
val y = b.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I<out I<out I<out I<out I<out kotlin.Any?>>>>>")!>y<!>
|
||||
val z = c.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I<out I<out I<out I<out I<out kotlin.Any?>>>>>..I<out I<out I<out I<out I<out kotlin.Any?>>>>>?!")!>z<!>
|
||||
}
|
||||
|
||||
fun javaClassTest(a: A2<*>, b: B2<*>, c: C2<*>, d: D2<*>) {
|
||||
a.foo()
|
||||
b.foo()
|
||||
c.foo()
|
||||
d.foo()
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
// FILE: I.java
|
||||
public interface I<G extends I<G>> {
|
||||
<T extends G> T foo();
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public class J<G extends J<G>> {
|
||||
<T extends G> void foo(T...args) {}
|
||||
}
|
||||
|
||||
// FILE: Main.kt
|
||||
class A1<G: A1<G>> : I<G> {
|
||||
override fun <T : G> foo(): T = TODO()
|
||||
}
|
||||
|
||||
class B1<G: I<G>> : I<G> {
|
||||
override fun <T : G> foo(): T = TODO()
|
||||
}
|
||||
|
||||
abstract class C1<G: I<G>> : I<G>
|
||||
|
||||
class A2<G: A2<G>> : J<G>() {}
|
||||
|
||||
class B2<G: J<G>> : J<G>() {}
|
||||
|
||||
class C2<G: C2<G>> : J<G>() {
|
||||
public override fun <T : G> foo(vararg args: T) {}
|
||||
}
|
||||
|
||||
class D2<G: J<G>> : J<G>() {
|
||||
public override fun <T : G> foo(vararg args: T) {}
|
||||
}
|
||||
|
||||
fun javaInterfaceTest(a: A1<*>, b: B1<*>, c: C1<*>) {
|
||||
val x = a.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("A1<*>")!>x<!>
|
||||
val y = b.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I<*>")!>y<!>
|
||||
val z = c.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(I<*>..I<*>?)")!>z<!>
|
||||
}
|
||||
|
||||
fun javaClassTest(a: A2<*>, b: B2<*>, c: C2<*>, d: D2<*>) {
|
||||
a.foo()
|
||||
b.foo()
|
||||
c.foo()
|
||||
d.foo()
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface I1<G : I1<G>> {
|
||||
fun <T : G> foo() : T
|
||||
fun <T : G> bar(vararg args: T)
|
||||
}
|
||||
|
||||
interface I2<in G : I2<G>> {
|
||||
fun <T : G> foo() : T
|
||||
fun <T : G> bar(vararg args: T)
|
||||
}
|
||||
|
||||
interface I3<G> where G : I3<G> {
|
||||
fun <T> foo() : T where T : G
|
||||
fun <T> bar(vararg args: T) where T : G
|
||||
}
|
||||
|
||||
fun test(a: I2<*>, b: I3<*>) {
|
||||
val x = a.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I2<kotlin.Nothing>")!>x<!>
|
||||
a.bar()
|
||||
val y = b.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I3<*>")!>y<!>
|
||||
b.bar()
|
||||
}
|
||||
|
||||
fun withTest(a: I1<*>, b: I3<*>) {
|
||||
with(a) {
|
||||
val x = foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I1<*>")!>x<!>
|
||||
bar()
|
||||
}
|
||||
with(b) {
|
||||
val y = foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I3<*>")!>y<!>
|
||||
bar()
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// ISSUE: KT-59012
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface I1<G : I1<G>> {
|
||||
fun <T : G> foo() : T
|
||||
fun <T : G> bar(vararg args: T)
|
||||
}
|
||||
|
||||
interface I2<in G : I2<G>> {
|
||||
fun <T : G> foo() : T
|
||||
fun <T : G> bar(vararg args: T)
|
||||
}
|
||||
|
||||
interface I3<G> where G : I3<G> {
|
||||
fun <T> foo() : T where T : G
|
||||
fun <T> bar(vararg args: T) where T : G
|
||||
}
|
||||
|
||||
fun test(a: I2<*>, b: I3<*>) {
|
||||
val x = a.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I2<*>")!>x<!>
|
||||
a.bar()
|
||||
val y = b.foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I3<*>")!>y<!>
|
||||
b.bar()
|
||||
}
|
||||
|
||||
fun withTest(a: I1<*>, b: I3<*>) {
|
||||
with(a) {
|
||||
val x = foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I1<*>")!>x<!>
|
||||
bar()
|
||||
}
|
||||
with(b) {
|
||||
val y = foo()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("I3<*>")!>y<!>
|
||||
bar()
|
||||
}
|
||||
}
|
||||
Generated
+18
@@ -19771,12 +19771,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumExtensionFunction.kt")
|
||||
public void testEnumExtensionFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/enumExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overridingJKCases.kt")
|
||||
public void testOverridingJKCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/overridingJKCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereAndWithCases.kt")
|
||||
public void testWhereAndWithCases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/whereAndWithCases.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user