From c63166047ca64f3803c3edb4a1cb1a3a02212ff9 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 23 May 2016 15:38:51 +0300 Subject: [PATCH] KT-11588 Type aliases Additional tests for type alias constructor & companion object: - codegen - error diagnostics --- .../box/typealias/typeAliasConstructor.kt | 5 +++ .../codegen/box/typealias/typeAliasObject.kt | 15 +++++++++ .../tests/typealias/typeAliasConstructor.kt | 14 ++++++++ .../tests/typealias/typeAliasConstructor.txt | 20 +++++++++++ .../typealias/typeAliasObjectWithInvoke.kt | 21 ++++++++++++ .../typealias/typeAliasObjectWithInvoke.txt | 33 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 +++++++ 8 files changed, 126 insertions(+) create mode 100644 compiler/testData/codegen/box/typealias/typeAliasConstructor.kt create mode 100644 compiler/testData/codegen/box/typealias/typeAliasObject.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.txt diff --git a/compiler/testData/codegen/box/typealias/typeAliasConstructor.kt b/compiler/testData/codegen/box/typealias/typeAliasConstructor.kt new file mode 100644 index 00000000000..d466f977248 --- /dev/null +++ b/compiler/testData/codegen/box/typealias/typeAliasConstructor.kt @@ -0,0 +1,5 @@ +class C(val x: String) + +typealias Alias = C + +fun box(): String = Alias("OK").x diff --git a/compiler/testData/codegen/box/typealias/typeAliasObject.kt b/compiler/testData/codegen/box/typealias/typeAliasObject.kt new file mode 100644 index 00000000000..203f4e5bd5f --- /dev/null +++ b/compiler/testData/codegen/box/typealias/typeAliasObject.kt @@ -0,0 +1,15 @@ +object OHolder { + val O = "O" +} + +typealias OHolderAlias = OHolder + +class KHolder { + companion object { + val K = "K" + } +} + +typealias KHolderAlias = KHolder + +fun box(): String = OHolderAlias.O + KHolderAlias.K diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt index d11b023ac3e..92e3023bdd6 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt @@ -8,3 +8,17 @@ val test1: C = TC("") val test2: TC = TC("") val test3: C = TC() val test4: TC = TC() + +val test5 = TC("", "") + +interface Interface +typealias TI = Interface + +object AnObject +typealias TO = AnObject + +val test6 = TI() +val test6a = Interface() + +val test7 = TO() +val test7a = AnObject() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt index 6d05d05b9ff..62b6d167e9c 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt @@ -1,10 +1,24 @@ package public typealias TC = C +public typealias TI = Interface +public typealias TO = AnObject public val test1: C public val test2: TC [= C] public val test3: C public val test4: TC [= C] +public val test5: [ERROR : Type for TC("", "")] +public val test6: [ERROR : Type for TI()] +public val test6a: [ERROR : Type for Interface()] +public val test7: [ERROR : Type for TO()] +public val test7a: [ERROR : Type for AnObject()] + +public object AnObject { + private constructor AnObject() + 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 +} public final class C { public constructor C() @@ -14,3 +28,9 @@ public final class C { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +public interface Interface { + 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 +} diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt new file mode 100644 index 00000000000..98dd13918c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt @@ -0,0 +1,21 @@ +object ObjectWithInvoke { + operator fun invoke() = this +} + +class ClassWithCompanionObjectWithInvoke { + companion object { + operator fun invoke(x: Any) = x + } +} + +typealias WI = ObjectWithInvoke + +typealias CWI = ClassWithCompanionObjectWithInvoke + +val test1 = WI() +val test2 = WI(null) + +val test3 = CWI() +val test4 = CWI("") +val test5 = CWI(null) +val test5a = ClassWithCompanionObjectWithInvoke(null) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.txt b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.txt new file mode 100644 index 00000000000..58ccc1dcebf --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.txt @@ -0,0 +1,33 @@ +package + +public typealias CWI = ClassWithCompanionObjectWithInvoke +public typealias WI = ObjectWithInvoke +public val test1: ObjectWithInvoke +public val test2: ObjectWithInvoke +public val test3: ClassWithCompanionObjectWithInvoke +public val test4: kotlin.Any +public val test5: ClassWithCompanionObjectWithInvoke +public val test5a: ClassWithCompanionObjectWithInvoke + +public final class ClassWithCompanionObjectWithInvoke { + public constructor ClassWithCompanionObjectWithInvoke() + 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 + + public companion object Companion { + private constructor Companion() + 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 final operator fun invoke(/*0*/ x: kotlin.Any): kotlin.Any + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public object ObjectWithInvoke { + private constructor ObjectWithInvoke() + 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 final operator fun invoke(): ObjectWithInvoke + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d71c279f2c0..86b2e26d694 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19190,6 +19190,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasObject.kt"); doTest(fileName); } + + @TestMetadata("typeAliasObjectWithInvoke.kt") + public void testTypeAliasObjectWithInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasObjectWithInvoke.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/tests/unit") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 841038c6fa9..808893086f2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -14370,6 +14370,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt"); doTest(fileName); } + + @TestMetadata("typeAliasConstructor.kt") + public void testTypeAliasConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("typeAliasObject.kt") + public void testTypeAliasObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/unaryOp")