From 0ff677596ff2216c6e230e843c93b66f12739a1b Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 10 Jun 2016 13:10:53 +0300 Subject: [PATCH] Modifiers checking for type aliases. Exposed type checking for type aliases. --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/resolve/AnnotationChecker.kt | 2 + .../kotlin/resolve/DeclarationsChecker.kt | 2 +- .../resolve/ExposedVisibilityChecker.kt | 12 +++ .../kotlin/resolve/ModifiersChecker.kt | 4 +- .../tests/typealias/exposedExpandedType.kt | 43 +++++++++++ .../tests/typealias/exposedExpandedType.txt | 73 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++ .../descriptors/annotations/KotlinTarget.kt | 1 + 10 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/exposedExpandedType.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index e06176aa021..87c8ff084c0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -85,6 +85,7 @@ public interface Errors { DiagnosticFactory3 EXPOSED_TYPE_PARAMETER_BOUND = DiagnosticFactory3.create(ERROR); DiagnosticFactory3 EXPOSED_SUPER_CLASS = DiagnosticFactory3.create(ERROR); DiagnosticFactory3 EXPOSED_SUPER_INTERFACE = DiagnosticFactory3.create(ERROR); + DiagnosticFactory3 EXPOSED_TYPEALIAS_EXPANDED_TYPE = DiagnosticFactory3.create(ERROR); DiagnosticFactory2> INACCESSIBLE_TYPE = DiagnosticFactory2.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 9bad0058c87..fbfd679791c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -106,6 +106,7 @@ public class DefaultErrorMessages { MAP.put(EXPOSED_TYPE_PARAMETER_BOUND, "''{0}'' generic exposes its ''{2}'' parameter bound type{1}", TO_STRING, TO_STRING, TO_STRING); MAP.put(EXPOSED_SUPER_CLASS, "''{0}'' subclass exposes its ''{2}'' supertype{1}", TO_STRING, TO_STRING, TO_STRING); MAP.put(EXPOSED_SUPER_INTERFACE, "''{0}'' sub-interface exposes its ''{2}'' supertype{1}", TO_STRING, TO_STRING, TO_STRING); + MAP.put(EXPOSED_TYPEALIAS_EXPANDED_TYPE, "''{0}'' typealias exposes ''{2}'' in expanded type{1}", TO_STRING, TO_STRING, TO_STRING); MAP.put(INACCESSIBLE_TYPE, "Type {0} is inaccessible in this context due to: {1}", RENDER_TYPE, RENDER_COLLECTION_OF_TYPES); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt index d0b19398b5a..3a6bf2dd7e4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt @@ -200,6 +200,7 @@ class AnnotationChecker(private val additionalCheckers: Iterable TargetLists.T_TYPEALIAS is KtPropertyAccessor -> if (annotated.isGetter) TargetLists.T_PROPERTY_GETTER else TargetLists.T_PROPERTY_SETTER is KtTypeReference -> TargetLists.T_TYPE_REFERENCE is KtFile -> TargetLists.T_FILE @@ -217,6 +218,7 @@ class AnnotationChecker(private val additionalCheckers: Iterable>( ENUM_KEYWORD to EnumSet.of(ENUM_CLASS), @@ -71,7 +71,7 @@ object ModifierCheckerCore { PUBLIC_KEYWORD to defaultVisibilityTargets, INTERNAL_KEYWORD to defaultVisibilityTargets, PROTECTED_KEYWORD to EnumSet.of(CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS, - MEMBER_FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, MEMBER_PROPERTY, CONSTRUCTOR), + MEMBER_FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, MEMBER_PROPERTY, CONSTRUCTOR, TYPEALIAS), IN_KEYWORD to EnumSet.of(TYPE_PARAMETER, TYPE_PROJECTION), OUT_KEYWORD to EnumSet.of(TYPE_PARAMETER, TYPE_PROJECTION), REIFIED_KEYWORD to EnumSet.of(TYPE_PARAMETER), diff --git a/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt new file mode 100644 index 00000000000..b8a866b27f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt @@ -0,0 +1,43 @@ +typealias L = List + +class Outer { + private class Private + protected class Protected + internal class Internal + + typealias TestPrivate1 = Private + protected typealias TestPrivate2 = Private + internal typealias TestPrivate3 = Private + private typealias TestPrivate4 = Private + typealias TestPrivate5 = L + typealias TestPrivate6 = L + + typealias TestProtected1 = Protected + protected typealias TestProtected2 = Protected + internal typealias TestProtected3 = Protected + private typealias TestProtected4 = Protected + typealias TestProtected5 = L + typealias TestProtected6 = L + + typealias TestInternal1 = Internal + protected typealias TestInternal2 = Internal + internal typealias TestInternal3 = Internal + private typealias TestInternal4 = Internal + typealias TestInternal5 = L + typealias TestInternal6 = L +} + +private class Private +internal class Internal + +typealias TestPrivate1 = Private +internal typealias TestPrivate2 = Private +private typealias TestPrivate3 = Private +typealias TestPrivate4 = L +typealias TestPrivate5 = L + +typealias TestInternal1 = Internal +internal typealias TestInternal2 = Internal +private typealias TestInternal3 = Internal +typealias TestInternal4 = L +typealias TestInternal5 = L diff --git a/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.txt b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.txt new file mode 100644 index 00000000000..2a46588100d --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.txt @@ -0,0 +1,73 @@ +package + +public typealias L = kotlin.collections.List +public typealias TestInternal1 = Internal +internal typealias TestInternal2 = Internal +private typealias TestInternal3 = Internal +public typealias TestInternal4 = L +public typealias TestInternal5 = L +public typealias TestPrivate1 = Private +internal typealias TestPrivate2 = Private +private typealias TestPrivate3 = Private +public typealias TestPrivate4 = L +public typealias TestPrivate5 = L + +internal final class Internal { + public constructor Internal() + 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 Outer { + public typealias TestInternal1 = Outer.Internal + protected typealias TestInternal2 = Outer.Internal + internal typealias TestInternal3 = Outer.Internal + private typealias TestInternal4 = Outer.Internal + public typealias TestInternal5 = L + public typealias TestInternal6 = L + public typealias TestPrivate1 = Outer.Private + protected typealias TestPrivate2 = Outer.Private + internal typealias TestPrivate3 = Outer.Private + private typealias TestPrivate4 = Outer.Private + public typealias TestPrivate5 = L + public typealias TestPrivate6 = L + public typealias TestProtected1 = Outer.Protected + protected typealias TestProtected2 = Outer.Protected + internal typealias TestProtected3 = Outer.Protected + private typealias TestProtected4 = Outer.Protected + public typealias TestProtected5 = L + public typealias TestProtected6 = L + public constructor Outer() + 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 final class Internal { + public constructor Internal() + 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 + } + + private final class Private { + public constructor Private() + 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 + } + + protected final class Protected { + public constructor Protected() + 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 + } +} + +private final class Private { + public constructor Private() + 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 ac292d24ce9..da28c3b54df 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19491,6 +19491,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("exposedExpandedType.kt") + public void testExposedExpandedType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt"); + doTest(fileName); + } + @TestMetadata("functionTypeInTypeAlias.kt") public void testFunctionTypeInTypeAlias() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/functionTypeInTypeAlias.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt index 4510254a99e..81930c58e66 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt @@ -38,6 +38,7 @@ enum class KotlinTarget(val description: String, val isDefault: Boolean = true) TYPE("type usage", false), EXPRESSION("expression", false), // includes FUNCTION_LITERAL, OBJECT_LITERAL FILE("file", false), + TYPEALIAS("typealias"), // TODO support typealias as annotation target TYPE_PROJECTION("type projection", false), STAR_PROJECTION("star projection", false),