From fced4756bb7d5e837ae39711cc013b9b64994990 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Fri, 5 Dec 2014 20:41:11 +0300 Subject: [PATCH] Add variance test for nullable and function types. --- .../tests/variance/FunctionTypes.kt | 12 +++++++ .../tests/variance/FunctionTypes.txt | 21 ++++++++++++ .../tests/variance/NullableTypes.kt | 16 +++++++++ .../tests/variance/NullableTypes.txt | 34 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 12 +++++++ 5 files changed, 95 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/variance/FunctionTypes.kt create mode 100644 compiler/testData/diagnostics/tests/variance/FunctionTypes.txt create mode 100644 compiler/testData/diagnostics/tests/variance/NullableTypes.kt create mode 100644 compiler/testData/diagnostics/tests/variance/NullableTypes.txt diff --git a/compiler/testData/diagnostics/tests/variance/FunctionTypes.kt b/compiler/testData/diagnostics/tests/variance/FunctionTypes.kt new file mode 100644 index 00000000000..e36928a1330 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/FunctionTypes.kt @@ -0,0 +1,12 @@ +trait In +fun getT(): T = null!! + +trait Test { + fun ok1(i: (O) -> I) : (I) -> O + fun ok2(i: (P) -> P) : (P) -> P + fun ok3(i: (In) -> In) = getT<(In) -> In>() + + fun neOk1(i: (I) -> O): (O) -> I + fun neOk2(i: (In<O>) -> In<I>) + fun neOk3() = getT<(In) -> In>() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/FunctionTypes.txt b/compiler/testData/diagnostics/tests/variance/FunctionTypes.txt new file mode 100644 index 00000000000..ff94d5130d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/FunctionTypes.txt @@ -0,0 +1,21 @@ +package + +internal fun getT(): T + +internal trait In { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal trait Test { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal abstract fun neOk1(/*0*/ i: (I) -> O): (O) -> I + internal abstract fun neOk2(/*0*/ i: (In) -> In): kotlin.Unit + internal open fun neOk3(): (In) -> In + internal abstract fun ok1(/*0*/ i: (O) -> I): (I) -> O + internal abstract fun ok2(/*0*/ i: (P) -> P): (P) -> P + internal open fun ok3(/*0*/ i: (In) -> In): (In) -> In + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/variance/NullableTypes.kt b/compiler/testData/diagnostics/tests/variance/NullableTypes.kt new file mode 100644 index 00000000000..1321ba9926c --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/NullableTypes.kt @@ -0,0 +1,16 @@ +trait In +trait Out +trait Inv

+fun getT(): T = null!! + + +trait Test { + fun ok1(i: I?) : O? + fun ok2(i: In?) : Out? + fun ok3(i: Inv) = getT>() + + fun neOk1(i: O?) : I? + fun neOk(i: Out<?)!>O?>?) : In<?)!>O?>? + fun neOk3(i: Inv)!>I?>) + ?)!>fun neOk4() = getT?>() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/NullableTypes.txt b/compiler/testData/diagnostics/tests/variance/NullableTypes.txt new file mode 100644 index 00000000000..534848de87f --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/NullableTypes.txt @@ -0,0 +1,34 @@ +package + +internal fun getT(): T + +internal trait In { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal trait Inv { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal trait Out { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal trait Test { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal abstract fun neOk(/*0*/ i: Out?): In? + internal abstract fun neOk1(/*0*/ i: O?): I? + internal abstract fun neOk3(/*0*/ i: Inv): kotlin.Unit + internal open fun neOk4(): Inv? + internal abstract fun ok1(/*0*/ i: I?): O? + internal abstract fun ok2(/*0*/ i: In?): Out? + internal open fun ok3(/*0*/ i: Inv): Inv + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 6438ef7fce1..4a048efc084 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -10304,6 +10304,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("FunctionTypes.kt") + public void testFunctionTypes() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/FunctionTypes.kt"); + doTest(fileName); + } + @TestMetadata("InPosition.kt") public void testInPosition() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/InPosition.kt"); @@ -10316,6 +10322,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("NullableTypes.kt") + public void testNullableTypes() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/NullableTypes.kt"); + doTest(fileName); + } + @TestMetadata("OutPosition.kt") public void testOutPosition() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/OutPosition.kt");