From bbec3bf00149b16889fa1c7e0e081961f25f78f8 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 22 May 2019 19:07:22 +0300 Subject: [PATCH] Fix exception on star import from typealias #KT-30983 Fixed --- .../fir/FirDiagnosticsSmokeTestGenerated.java | 5 +++ .../resolve/QualifiedExpressionResolver.kt | 6 ++- ...arImportOfExpectEnumWithActualTypeAlias.kt | 30 +++++++++++++ .../typealias/importMemberFromJavaViaAlias.kt | 1 + .../tests/typealias/starImportOnTypeAlias.kt | 30 +++++++++++++ .../tests/typealias/starImportOnTypeAlias.txt | 42 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 5 +++ .../DiagnosticsUsingJavacTestGenerated.java | 5 +++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 13 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.txt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 303622b99c0..8091468eb25 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -22551,6 +22551,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.kt"); } + @TestMetadata("starImportOnTypeAlias.kt") + public void testStarImportOnTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt"); + } + @TestMetadata("starProjection.kt") public void testStarProjection() throws Exception { runTest("compiler/testData/diagnostics/tests/typealias/starProjection.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt index 9f4621519e3..986004d7b96 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt @@ -231,7 +231,7 @@ class QualifiedExpressionResolver { val packageOrClassDescriptor = resolveToPackageOrClass( path, moduleDescriptor, trace, packageFragmentForCheck, scopeForFirstPart = null, position = QualifierPosition.IMPORT - ) ?: return null + ).classDescriptorFromTypeAlias() ?: return null if (packageOrClassDescriptor is ClassDescriptor && packageOrClassDescriptor.kind.isSingleton && lastPart.expression != null) { trace.report( @@ -249,6 +249,10 @@ class QualifiedExpressionResolver { } } + private fun DeclarationDescriptor?.classDescriptorFromTypeAlias(): DeclarationDescriptor? { + return if (this is TypeAliasDescriptor) classDescriptor else this + } + private fun computePackageFragmentToCheck( containingFile: KtFile, packageFragmentForVisibilityCheck: PackageFragmentDescriptor? diff --git a/compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt b/compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt new file mode 100644 index 00000000000..7188b314310 --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +MultiPlatformProjects +// IGNORE_BACKEND: JS +// IGNORE_BACKEND: JS_IR + +// MODULE: common +// FILE: common.kt + +package test + +expect enum class E + +// MODULE: jvm1(common) +// FILE: jvm.kt + +package test + +actual typealias E = F + +enum class F { + OK; +} + +// MODULE: main(jvm1) +// FILE: jvm2.kt + +import test.E.* + +fun box(): String { + return OK.name +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.kt b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.kt index 28aa08a87d7..07cedb5ffff 100644 --- a/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.kt +++ b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_JAVAC // FILE: test/jv/JavaSample.java diff --git a/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt new file mode 100644 index 00000000000..d1e6dcbfc52 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt @@ -0,0 +1,30 @@ +// FILE: foo.kt + +// FILE: foo.kt + +package test + +typealias ClassAlias = ClassSample +typealias ObjectAlias = ObjectSample +typealias EnumAlias = EnumSample + +class ClassSample + +object ObjectSample + +enum class EnumSample { + Entry; +} + +// FILE: bar.kt + +import test.ClassAlias.* +import test.ObjectAlias.* +import test.EnumAlias.* +import test.EnumAlias + + +fun bar() { + Entry + EnumAlias.Entry +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.txt b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.txt new file mode 100644 index 00000000000..6189abd51c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.txt @@ -0,0 +1,42 @@ +package + +public fun bar(): kotlin.Unit + +package test { + + public final class ClassSample { + public constructor ClassSample() + 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 enum class EnumSample : kotlin.Enum { + enum entry Entry + + private constructor EnumSample() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: test.EnumSample): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.EnumSample + public final /*synthesized*/ fun values(): kotlin.Array + } + + public object ObjectSample { + private constructor ObjectSample() + 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 typealias ClassAlias = test.ClassSample + public typealias EnumAlias = test.EnumSample + public typealias ObjectAlias = test.ObjectSample +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 03ad4c6f582..10df9d65378 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -22633,6 +22633,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.kt"); } + @TestMetadata("starImportOnTypeAlias.kt") + public void testStarImportOnTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt"); + } + @TestMetadata("starProjection.kt") public void testStarProjection() throws Exception { runTest("compiler/testData/diagnostics/tests/typealias/starProjection.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 72dda0aa0b2..7eebe788465 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -22553,6 +22553,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/typealias/simpleTypeAlias.kt"); } + @TestMetadata("starImportOnTypeAlias.kt") + public void testStarImportOnTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.kt"); + } + @TestMetadata("starProjection.kt") public void testStarProjection() throws Exception { runTest("compiler/testData/diagnostics/tests/typealias/starProjection.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 1a061e31d0d..c9b41bc99a9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16068,6 +16068,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/multiplatform/optionalExpectationJvm.kt"); } + @TestMetadata("starImportOfExpectEnumWithActualTypeAlias.kt") + public void testStarImportOfExpectEnumWithActualTypeAlias() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt"); + } + @TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index fe1cf5216a3..1b241a67d64 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16068,6 +16068,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/multiplatform/optionalExpectationJvm.kt"); } + @TestMetadata("starImportOfExpectEnumWithActualTypeAlias.kt") + public void testStarImportOfExpectEnumWithActualTypeAlias() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt"); + } + @TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index ada29893928..ad00a4fe857 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -16073,6 +16073,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/multiplatform/optionalExpectationJvm.kt"); } + @TestMetadata("starImportOfExpectEnumWithActualTypeAlias.kt") + public void testStarImportOfExpectEnumWithActualTypeAlias() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt"); + } + @TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index ca992224838..04511686b48 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -12293,6 +12293,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt"); } + @TestMetadata("starImportOfExpectEnumWithActualTypeAlias.kt") + public void testStarImportOfExpectEnumWithActualTypeAlias() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt"); + } + @TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 219cf5c4a75..e395984be12 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -13448,6 +13448,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt"); } + @TestMetadata("starImportOfExpectEnumWithActualTypeAlias.kt") + public void testStarImportOfExpectEnumWithActualTypeAlias() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/starImportOfExpectEnumWithActualTypeAlias.kt"); + } + @TestMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)