From 1329a43d89eb4773a2cb23ba9cc9495f63d3877e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 23 May 2016 15:31:01 +0300 Subject: [PATCH] KT-11588 Type aliases Type alias constructor --- .../kotlin/resolve/calls/tower/TowerLevels.kt | 5 ++++- .../typealias/genericTypeAliasConstructor.kt | 10 ++++++++++ .../typealias/genericTypeAliasConstructor.txt | 17 +++++++++++++++++ .../tests/typealias/typeAliasConstructor.kt | 10 ++++++++++ .../tests/typealias/typeAliasConstructor.txt | 16 ++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 12 ++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.txt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index 6380aea714f..9687fe48c49 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -256,7 +256,10 @@ private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeC } private fun getClassWithConstructors(classifier: ClassifierDescriptor?): ClassDescriptor? { - if (classifier !is ClassDescriptor || ErrorUtils.isError(classifier) + if (classifier is TypeAliasDescriptor) { + return getClassWithConstructors(classifier.classDescriptor) + } + else if (classifier !is ClassDescriptor || ErrorUtils.isError(classifier) // Constructors of singletons shouldn't be callable from the code || classifier.kind.isSingleton) { return null diff --git a/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.kt b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.kt new file mode 100644 index 00000000000..fd683ffa156 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.kt @@ -0,0 +1,10 @@ +class C(val x: T, val y: String) { + constructor(x: T): this(x, "") +} + +typealias GTC = C + +val test1 = GTC("", "") +val test2 = GTC("", "") +val test3 = GTC("") +val test4 = GTC("") diff --git a/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.txt b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.txt new file mode 100644 index 00000000000..98a723012f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.txt @@ -0,0 +1,17 @@ +package + +public typealias GTC = C +public val test1: C +public val test2: C +public val test3: C +public val test4: C + +public final class C { + public constructor C(/*0*/ x: T) + public constructor C(/*0*/ x: T, /*1*/ y: kotlin.String) + public final val x: T + public final val y: kotlin.String + 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/typeAliasConstructor.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt new file mode 100644 index 00000000000..d11b023ac3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt @@ -0,0 +1,10 @@ +class C(val x: String) { + constructor(): this("") +} + +typealias TC = C + +val test1: C = TC("") +val test2: TC = TC("") +val test3: C = TC() +val test4: TC = TC() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt new file mode 100644 index 00000000000..6d05d05b9ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.txt @@ -0,0 +1,16 @@ +package + +public typealias TC = C +public val test1: C +public val test2: TC [= C] +public val test3: C +public val test4: TC [= C] + +public final class C { + public constructor C() + public constructor C(/*0*/ x: kotlin.String) + public final val x: kotlin.String + 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/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index f4bc3bb8c1d..d71c279f2c0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19131,6 +19131,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/typealias"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("genericTypeAliasConstructor.kt") + public void testGenericTypeAliasConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/genericTypeAliasConstructor.kt"); + doTest(fileName); + } + @TestMetadata("genericTypeAliasObject.kt") public void testGenericTypeAliasObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/genericTypeAliasObject.kt"); @@ -19173,6 +19179,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("typeAliasConstructor.kt") + public void testTypeAliasConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt"); + doTest(fileName); + } + @TestMetadata("typeAliasObject.kt") public void testTypeAliasObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasObject.kt");