diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 7504304d5e1..194371371ba 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -130,6 +130,7 @@ public interface Errors { DiagnosticFactory0 REIFIED_TYPE_IN_CATCH_CLAUSE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 GENERIC_THROWABLE_SUBCLASS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 TOPLEVEL_TYPEALIASES_ONLY = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 RECURSIVE_TYPEALIAS_EXPANSION = DiagnosticFactory1.create(ERROR); DiagnosticFactory3 UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION = DiagnosticFactory3.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 6ebfa9c9652..2c42764f4c1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -434,6 +434,7 @@ public class DefaultErrorMessages { MAP.put(USELESS_ELVIS_RIGHT_IS_NULL, "Right operand of elvis operator (?:) is useless if it is null"); MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME); + MAP.put(TOPLEVEL_TYPEALIASES_ONLY, "Nested and local type aliases are not supported"); MAP.put(RECURSIVE_TYPEALIAS_EXPANSION, "Recursive type alias in expansion: {0}", NAME); MAP.put(UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION, "Type argument resulting from type alias expansion is not within required bounds for ''{2}'': " + diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index d62fc438cbb..7dd21eff761 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -661,6 +661,10 @@ public class DescriptorResolver { @NotNull KtTypeAlias typeAlias, @NotNull final BindingTrace trace ) { + if (!(containingDeclaration instanceof PackageFragmentDescriptor)) { + trace.report(TOPLEVEL_TYPEALIASES_ONLY.on(typeAlias)); + } + KtModifierList modifierList = typeAlias.getModifierList(); Visibility visibility = resolveVisibilityFromModifiers(typeAlias, getDefaultVisibility(typeAlias, containingDeclaration)); diff --git a/compiler/testData/codegen/box/annotations/annotationsOnTypeAliases.kt b/compiler/testData/codegen/box/annotations/annotationsOnTypeAliases.kt index d64dc4455ad..3e49c7af76d 100644 --- a/compiler/testData/codegen/box/annotations/annotationsOnTypeAliases.kt +++ b/compiler/testData/codegen/box/annotations/annotationsOnTypeAliases.kt @@ -12,11 +12,6 @@ import java.lang.Class @Retention(RUNTIME) annotation class Ann(val x: Int) -class C { - @Ann(1) - typealias TA = Any -} - @Ann(2) typealias TA = Any @@ -28,7 +23,6 @@ fun Class<*>.assertHasDeclaredMethodWithAnn() { fun box(): String { Class.forName("AnnotationsOnTypeAliasesKt").assertHasDeclaredMethodWithAnn() - Class.forName("C").assertHasDeclaredMethodWithAnn() return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/typealias/localTypeAlias.kt b/compiler/testData/codegen/box/typealias/localTypeAlias.kt deleted file mode 100644 index 406bbaaf675..00000000000 --- a/compiler/testData/codegen/box/typealias/localTypeAlias.kt +++ /dev/null @@ -1,16 +0,0 @@ -class Cell(val x: TC) - -object OkHost { - val value = "OK" -} - -fun id(x: T): T { - typealias C = Cell - val c: C = C(x) - return c.x -} - -fun box(): String { - typealias OK = OkHost - return id(OK.value) -} \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/typeAliases.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/typeAliases.kt index a2733f9cde4..cebf94074ef 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/typeAliases.kt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/typeAliases.kt @@ -4,6 +4,7 @@ typealias Str = String typealias L = List class Klass { + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias Nested = Z class Z diff --git a/compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt b/compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt index 5f543474085..1bb272ce4f9 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt @@ -9,11 +9,6 @@ import java.lang.Class @Retention(RUNTIME) annotation class Ann(val x: Int) -class C { - @Ann(1) - typealias TA = Any -} - @Ann(2) typealias TA = Any @@ -28,7 +23,6 @@ fun Class<*>.assertHasDeclaredMethodWithAnn() { fun box(): String { Class.forName("a.AKt").assertHasDeclaredMethodWithAnn() - Class.forName("a.C").assertHasDeclaredMethodWithAnn() return "OK" } \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstKotlin/typeAliasesKt13181.kt b/compiler/testData/compileKotlinAgainstKotlin/typeAliasesKt13181.kt index 36af0a7041d..101c79e0cbd 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/typeAliasesKt13181.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/typeAliasesKt13181.kt @@ -1,14 +1,15 @@ // FILE: A.kt -class Foo(val t: T) { - typealias Bar = (T) -> String +typealias Bar = (T) -> String - fun baz(b: Bar) = b(t) +class Foo(val t: T) { + + fun baz(b: Bar) = b(t) } // FILE: B.kt class FooTest { fun baz(): String { - val b: Foo.Bar = { "OK" } + val b: Bar = { "OK" } return Foo("").baz(b) } } diff --git a/compiler/testData/diagnostics/tests/Underscore.kt b/compiler/testData/diagnostics/tests/Underscore.kt index 57628b74cdd..c105b42c706 100644 --- a/compiler/testData/diagnostics/tests/Underscore.kt +++ b/compiler/testData/diagnostics/tests/Underscore.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -DEPRECATION +// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY import kotlin.Deprecated as ___ diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.kt index e18c775114d..e3eb0306134 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClasses.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // !CHECK_TYPE open class Outer { inner class Inner diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.kt index 842ef7c9f31..9c539118aaf 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocal.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY class A diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.kt index 567138ce181..9828d09cbf6 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesLocalInsideInner.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER +// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY class A diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.kt index 999d7b35805..cad9c6080c1 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromSuperClassesTransitive.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // !CHECK_TYPE open class Outer { inner class Inner diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.kt index 0dbe690a9b7..cfc7154da29 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasCtorVsFun.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY class C(val x: Int) typealias CC = C diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt index 91ca8217ae6..09cab9f306e 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsClass.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // FILE: file1.kt class SomeClass diff --git a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.kt b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.kt index 8ec4cbb1da4..c5ed0d0fccf 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/TypeAliasVsProperty.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // FILE: file1.kt typealias Test = String diff --git a/compiler/testData/diagnostics/tests/typealias/aliasesOnly.kt b/compiler/testData/diagnostics/tests/typealias/aliasesOnly.kt index 61663d1776a..6d283e0cf15 100644 --- a/compiler/testData/diagnostics/tests/typealias/aliasesOnly.kt +++ b/compiler/testData/diagnostics/tests/typealias/aliasesOnly.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + typealias S = String class C { diff --git a/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.kt b/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.kt index 80e6fb8b3c5..2c65e384b2a 100644 --- a/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.kt +++ b/compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY class Outer { typealias LTO = List diff --git a/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt index b8a866b27f5..95b74061881 100644 --- a/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt +++ b/compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + typealias L = List class Outer { diff --git a/compiler/testData/diagnostics/tests/typealias/import.kt b/compiler/testData/diagnostics/tests/typealias/import.kt index 53769ee9cea..d370c3d0978 100644 --- a/compiler/testData/diagnostics/tests/typealias/import.kt +++ b/compiler/testData/diagnostics/tests/typealias/import.kt @@ -1,3 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // FILE: file1.kt package package1 diff --git a/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.kt b/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.kt index 2aec76fb48d..d0e84053c88 100644 --- a/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.kt +++ b/compiler/testData/diagnostics/tests/typealias/inheritedNestedTypeAlias.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + interface ICell { val x: T } diff --git a/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.kt b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.kt index 56e21d660e4..82ed7bc5acf 100644 --- a/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.kt +++ b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY open class Base { typealias Nested = String diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt index a47821a691c..e18864204f0 100644 --- a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class Outer { class Nested class GenericNested diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.kt index e51653d15ef..f1a2018e98d 100644 --- a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.kt +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class C { inner class D diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt index fe4f8812f82..f870fa0a89b 100644 --- a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class Pair(val x: X, val y: Y) class C { diff --git a/compiler/testData/diagnostics/tests/typealias/kt14518.kt b/compiler/testData/diagnostics/tests/typealias/kt14518.kt index df4b929eaa7..bfc2ceb1008 100644 --- a/compiler/testData/diagnostics/tests/typealias/kt14518.kt +++ b/compiler/testData/diagnostics/tests/typealias/kt14518.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class OuterClass { class NestedClass typealias NestedType = NestedClass diff --git a/compiler/testData/diagnostics/tests/typealias/kt14641.kt b/compiler/testData/diagnostics/tests/typealias/kt14641.kt index d9a1dfa847e..19cce4033ae 100644 --- a/compiler/testData/diagnostics/tests/typealias/kt14641.kt +++ b/compiler/testData/diagnostics/tests/typealias/kt14641.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class A { public inner class B { } public typealias BAlias = B diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAlias.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.kt index 7ff40630d07..a7c55d93331 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAlias.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY fun emptyList(): List = null!! diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.kt index 39dfb06c5dc..d8fca8bb127 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY class Cell(val x: TC) diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.kt index d08d1b5e6aa..d3d24d7c4ac 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasModifiers.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + fun outer() { companion typealias TestLocal = Any } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.kt index b84a1be05c5..8db07dd92f5 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasRecursive.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + fun outer() { typealias Test1 = Test1 typealias Test2 = List diff --git a/compiler/testData/diagnostics/tests/typealias/nested.kt b/compiler/testData/diagnostics/tests/typealias/nested.kt index 0916f68de9b..b895319f19a 100644 --- a/compiler/testData/diagnostics/tests/typealias/nested.kt +++ b/compiler/testData/diagnostics/tests/typealias/nested.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY class Pair(val x1: T1, val x2: T2) diff --git a/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.kt b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.kt index 67fbafb45f6..b908bce1e04 100644 --- a/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.kt +++ b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class Pair(val x1: T1, val x2: T2) class C { diff --git a/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.kt b/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.kt index b045cd7bbdc..e5ec2fb2f50 100644 --- a/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.kt +++ b/compiler/testData/diagnostics/tests/typealias/nestedSubstituted.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY class Pair(val x1: T1, val x2: T2) diff --git a/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.kt b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.kt new file mode 100644 index 00000000000..f5b85f53ba4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.kt @@ -0,0 +1,19 @@ +typealias TopLevel = Any + +interface A { + typealias Nested = Any +} + +class C { + typealias Nested = Any + class D { + typealias Nested = Any + fun foo() { + typealias LocalInMember = Any + } + } +} + +fun foo() { + typealias Local = Any +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.txt b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.txt new file mode 100644 index 00000000000..a3328cb0775 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.txt @@ -0,0 +1,28 @@ +package + +public fun foo(): kotlin.Unit + +public interface A { + 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 Nested = kotlin.Any +} + +public final class C { + public constructor C() + 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 D { + public constructor D() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public typealias Nested = kotlin.Any + } + public typealias Nested = kotlin.Any +} +public typealias TopLevel = kotlin.Any diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.kt index a3bfa09e3d9..75ab9223ce8 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsBareType.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + typealias L = List typealias NL = List? typealias LStar<T> = List<*> diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.kt index 05530955c77..b8872860e74 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsQualifier.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + class C { typealias Self = C class Nested { diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.kt index 8f0ab7e25ab..749d9156199 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + open class Base { open fun foo() {} } diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.kt index 6dcfef457ed..c2a6412fd1e 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + abstract class AbstractClass typealias Test1 = AbstractClass val test1 = Test1() diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.kt index c61c176063c..cb983b263cb 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.kt @@ -1,3 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY + typealias ToTypeParam1 = T typealias ToTypeParam2 = ToTypeParam1 typealias ToTypeParam3T2> = ToTypeParam2 diff --git a/compiler/testData/ir/irText/declarations/typeAlias.kt b/compiler/testData/ir/irText/declarations/typeAlias.kt index 9b366d74dd5..78a67277d76 100644 --- a/compiler/testData/ir/irText/declarations/typeAlias.kt +++ b/compiler/testData/ir/irText/declarations/typeAlias.kt @@ -1,9 +1,11 @@ typealias Test1 = String fun foo() { + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias TestLocal = String } class C { + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias TestNested = String } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt b/compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt deleted file mode 100644 index 263571951e8..00000000000 --- a/compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt +++ /dev/null @@ -1,18 +0,0 @@ -//ALLOW_AST_ACCESS -package test - -open class Pair -open class Triple - -class Outer { - inner class InnerTest1: Pair() - typealias Test1 = Pair - - class Nested { - typealias Test2 = Pair - } - - inner class Inner { - typealias Test3 = Triple - } -} diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Nested.txt b/compiler/testData/loadJava/compiledKotlin/typealias/Nested.txt deleted file mode 100644 index a8908a84e3b..00000000000 --- a/compiler/testData/loadJava/compiledKotlin/typealias/Nested.txt +++ /dev/null @@ -1,28 +0,0 @@ -package test - -public final class Outer { - /*primary*/ public constructor Outer() - - public final inner class Inner /*captured type parameters: /*1*/ X*/ { - /*primary*/ public constructor Inner() - public typealias Test3 /*captured type parameters: /*1*/ Z, /*2*/ X*/ = test.Triple - } - - public final inner class InnerTest1 /*captured type parameters: /*1*/ X*/ : test.Pair { - /*primary*/ public constructor InnerTest1() - } - - public final class Nested { - /*primary*/ public constructor Nested() - public typealias Test2 /*captured type parameters: /*1*/ Y*/ = test.Pair - } - public typealias Test1 /*captured type parameters: /*1*/ X*/ = test.Pair -} - -public open class Pair { - /*primary*/ public constructor Pair() -} - -public open class Triple { - /*primary*/ public constructor Triple() -} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 3217dde5595..3c1550df7bc 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -16193,12 +16193,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } - @TestMetadata("localTypeAlias.kt") - public void testLocalTypeAlias() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/localTypeAlias.kt"); - doTest(fileName); - } - @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 78bdf86f06e..7eddcd81531 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -21106,6 +21106,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("topLevelTypeAliasesOnly.kt") + public void testTopLevelTypeAliasesOnly() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/topLevelTypeAliasesOnly.kt"); + doTest(fileName); + } + @TestMetadata("typeAliasArgumentsInCompanionObject.kt") public void testTypeAliasArgumentsInCompanionObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 6a75b67f035..d83f5816943 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16193,12 +16193,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("localTypeAlias.kt") - public void testLocalTypeAlias() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/localTypeAlias.kt"); - doTest(fileName); - } - @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index f63605e1776..0e5ab3715d1 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -4837,12 +4837,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); doTestCompiledKotlin(fileName); } - - @TestMetadata("Nested.kt") - public void testNested() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt"); - doTestCompiledKotlin(fileName); - } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java index 5321b9a246a..4c8223a122b 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java @@ -3070,12 +3070,6 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); doTest(fileName); } - - @TestMetadata("Nested.kt") - public void testNested() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt"); - doTest(fileName); - } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index 0b1fcad2eef..05219ad1a15 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -3072,12 +3072,6 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); doTest(fileName); } - - @TestMetadata("Nested.kt") - public void testNested() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt"); - doTest(fileName); - } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt index f54c790d63a..abe2a9974d1 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt @@ -260,12 +260,12 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT val toBeShortened: Boolean when (result) { - is ShortenNow -> { + is AnalyzeQualifiedElementResult.ShortenNow -> { elementsToShorten.add(element) toBeShortened = true } - is ImportDescriptors -> { + is AnalyzeQualifiedElementResult.ImportDescriptors -> { val tryImport = result.descriptors.isNotEmpty() && result.descriptors.none { it in failedToImportDescriptors } && result.descriptors.all { mayImport(it, file) } @@ -278,7 +278,7 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT } } - is Skip -> { + is AnalyzeQualifiedElementResult.Skip -> { toBeShortened = false } } @@ -305,10 +305,6 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT class ImportDescriptors(val descriptors: Collection) : AnalyzeQualifiedElementResult() } - typealias Skip = AnalyzeQualifiedElementResult.Skip - typealias ShortenNow = AnalyzeQualifiedElementResult.ShortenNow - typealias ImportDescriptors = AnalyzeQualifiedElementResult.ImportDescriptors - protected abstract fun shortenElement(element: TElement): KtElement fun shortenElements(elementSetToUpdate: MutableSet) { @@ -357,10 +353,10 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT } override fun analyzeQualifiedElement(element: KtUserType, bindingContext: BindingContext): AnalyzeQualifiedElementResult { - if (element.qualifier == null) return Skip - val referenceExpression = element.referenceExpression ?: return Skip + if (element.qualifier == null) return AnalyzeQualifiedElementResult.Skip + val referenceExpression = element.referenceExpression ?: return AnalyzeQualifiedElementResult.Skip - val target = referenceExpression.targets(bindingContext).singleOrNull() ?: return Skip + val target = referenceExpression.targets(bindingContext).singleOrNull() ?: return AnalyzeQualifiedElementResult.Skip val scope = element.getResolutionScope(bindingContext, resolutionFacade) val name = target.name @@ -370,7 +366,7 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT scope.findPackage(name) val canShortenNow = targetByName?.asString() == target.asString() - return if (canShortenNow) ShortenNow else ImportDescriptors(target.singletonOrEmptyList()) + return if (canShortenNow) AnalyzeQualifiedElementResult.ShortenNow else AnalyzeQualifiedElementResult.ImportDescriptors(target.singletonOrEmptyList()) } override fun shortenElement(element: KtUserType): KtElement { @@ -421,17 +417,17 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT override fun analyzeQualifiedElement(element: KtDotQualifiedExpression, bindingContext: BindingContext): AnalyzeQualifiedElementResult { val receiver = element.receiverExpression - if (receiver !is KtThisExpression && bindingContext[BindingContext.QUALIFIER, receiver] == null) return Skip + if (receiver !is KtThisExpression && bindingContext[BindingContext.QUALIFIER, receiver] == null) return AnalyzeQualifiedElementResult.Skip if (PsiTreeUtil.getParentOfType( element, - KtImportDirective::class.java, KtPackageDirective::class.java) != null) return Skip + KtImportDirective::class.java, KtPackageDirective::class.java) != null) return AnalyzeQualifiedElementResult.Skip - val selector = element.selectorExpression ?: return Skip - val callee = selector.getCalleeExpressionIfAny() as? KtReferenceExpression ?: return Skip + val selector = element.selectorExpression ?: return AnalyzeQualifiedElementResult.Skip + val callee = selector.getCalleeExpressionIfAny() as? KtReferenceExpression ?: return AnalyzeQualifiedElementResult.Skip val targets = callee.targets(bindingContext) val varAsFunResolvedCall = callee.getResolvedCall(bindingContext) as? VariableAsFunctionResolvedCall - if (targets.isEmpty()) return Skip + if (targets.isEmpty()) return AnalyzeQualifiedElementResult.Skip val (newContext, selectorCopy) = copyAndAnalyzeSelector(element, bindingContext) val newCallee = selectorCopy.getCalleeExpressionIfAny() as KtReferenceExpression @@ -441,27 +437,27 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT && (varAsFunResolvedCall == null || resolvedCallsMatch(varAsFunResolvedCall, varAsFunResolvedCallWhenShort)) if (receiver is KtThisExpression) { - if (!targetsMatch) return Skip - val originalCall = selector.getResolvedCall(bindingContext) ?: return Skip - val newCall = selectorCopy.getResolvedCall(newContext) ?: return Skip + if (!targetsMatch) return AnalyzeQualifiedElementResult.Skip + val originalCall = selector.getResolvedCall(bindingContext) ?: return AnalyzeQualifiedElementResult.Skip + val newCall = selectorCopy.getResolvedCall(newContext) ?: return AnalyzeQualifiedElementResult.Skip val receiverKind = originalCall.explicitReceiverKind val newReceiver = when (receiverKind) { ExplicitReceiverKind.BOTH_RECEIVERS, ExplicitReceiverKind.EXTENSION_RECEIVER -> newCall.extensionReceiver ExplicitReceiverKind.DISPATCH_RECEIVER -> newCall.dispatchReceiver - else -> return Skip - } as? ImplicitReceiver ?: return Skip + else -> return AnalyzeQualifiedElementResult.Skip + } as? ImplicitReceiver ?: return AnalyzeQualifiedElementResult.Skip val thisTarget = receiver.instanceReference.targets(bindingContext).singleOrNull() - if (newReceiver.declarationDescriptor.asString() != thisTarget?.asString()) return Skip + if (newReceiver.declarationDescriptor.asString() != thisTarget?.asString()) return AnalyzeQualifiedElementResult.Skip } return when { - targetsMatch -> ShortenNow + targetsMatch -> AnalyzeQualifiedElementResult.ShortenNow // it makes no sense to insert import when there is a conflict with function, property etc - targetsWhenShort.any { it !is ClassDescriptor && it !is PackageViewDescriptor } -> Skip + targetsWhenShort.any { it !is ClassDescriptor && it !is PackageViewDescriptor } -> AnalyzeQualifiedElementResult.Skip - else -> ImportDescriptors(targets) + else -> AnalyzeQualifiedElementResult.ImportDescriptors(targets) } } @@ -519,10 +515,10 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT } override fun analyzeQualifiedElement(element: KtThisExpression, bindingContext: BindingContext): AnalyzeQualifiedElementResult { - val targetBefore = element.instanceReference.targets(bindingContext).singleOrNull() ?: return Skip + val targetBefore = element.instanceReference.targets(bindingContext).singleOrNull() ?: return AnalyzeQualifiedElementResult.Skip val newContext = simpleThis.analyzeAsReplacement(element, bindingContext, resolutionFacade) val targetAfter = simpleThis.instanceReference.targets(newContext).singleOrNull() - return if (targetBefore == targetAfter) ShortenNow else Skip + return if (targetBefore == targetAfter) AnalyzeQualifiedElementResult.ShortenNow else AnalyzeQualifiedElementResult.Skip } override fun shortenElement(element: KtThisExpression): KtElement { @@ -545,27 +541,27 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT if (PsiTreeUtil.getParentOfType( element, - KtImportDirective::class.java, KtPackageDirective::class.java) != null) return Skip + KtImportDirective::class.java, KtPackageDirective::class.java) != null) return AnalyzeQualifiedElementResult.Skip - val receiverTarget = receiver.singleTarget(bindingContext) as? ClassDescriptor ?: return Skip + val receiverTarget = receiver.singleTarget(bindingContext) as? ClassDescriptor ?: return AnalyzeQualifiedElementResult.Skip - val selectorExpression = element.selectorExpression ?: return Skip - val selectorTarget = selectorExpression.singleTarget(bindingContext) ?: return Skip + val selectorExpression = element.selectorExpression ?: return AnalyzeQualifiedElementResult.Skip + val selectorTarget = selectorExpression.singleTarget(bindingContext) ?: return AnalyzeQualifiedElementResult.Skip - if (receiverTarget.companionObjectDescriptor != selectorTarget) return Skip + if (receiverTarget.companionObjectDescriptor != selectorTarget) return AnalyzeQualifiedElementResult.Skip val selectorsSelector = (element.parent as? KtDotQualifiedExpression)?.selectorExpression - ?: return ShortenNow + ?: return AnalyzeQualifiedElementResult.ShortenNow - val selectorsSelectorTarget = selectorsSelector.singleTarget(bindingContext) ?: return Skip - if (selectorsSelectorTarget is ClassDescriptor) return Skip + val selectorsSelectorTarget = selectorsSelector.singleTarget(bindingContext) ?: return AnalyzeQualifiedElementResult.Skip + if (selectorsSelectorTarget is ClassDescriptor) return AnalyzeQualifiedElementResult.Skip // TODO: More generic solution may be possible if (selectorsSelectorTarget is PropertyDescriptor) { val source = selectorsSelectorTarget.source.getPsi() as? KtProperty - if (source != null && isEnumCompanionPropertyWithEntryConflict(source, source.name ?: "")) return Skip + if (source != null && isEnumCompanionPropertyWithEntryConflict(source, source.name ?: "")) return AnalyzeQualifiedElementResult.Skip } - return ShortenNow + return AnalyzeQualifiedElementResult.ShortenNow } override fun shortenElement(element: KtDotQualifiedExpression): KtElement { diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java index ddec537c280..0f1bc2cacca 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java @@ -3070,12 +3070,6 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); doTest(fileName); } - - @TestMetadata("Nested.kt") - public void testNested() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Nested.kt"); - doTest(fileName); - } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") diff --git a/jps-plugin/testData/incremental/pureKotlin/addMemberTypeAlias/a.kt.new b/jps-plugin/testData/incremental/pureKotlin/addMemberTypeAlias/a.kt.new index 2f651d8a0c9..b1b7bcb0377 100644 --- a/jps-plugin/testData/incremental/pureKotlin/addMemberTypeAlias/a.kt.new +++ b/jps-plugin/testData/incremental/pureKotlin/addMemberTypeAlias/a.kt.new @@ -3,7 +3,9 @@ package a class Outer { inner class B(x: String) + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias A1 = B + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") private typealias A2 = B fun A1(x: Any) = x diff --git a/jps-plugin/testData/incremental/pureKotlin/removeMemberTypeAlias/a.kt b/jps-plugin/testData/incremental/pureKotlin/removeMemberTypeAlias/a.kt index 2f651d8a0c9..6a5080369a0 100644 --- a/jps-plugin/testData/incremental/pureKotlin/removeMemberTypeAlias/a.kt +++ b/jps-plugin/testData/incremental/pureKotlin/removeMemberTypeAlias/a.kt @@ -3,7 +3,10 @@ package a class Outer { inner class B(x: String) + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias A1 = B + + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") private typealias A2 = B fun A1(x: Any) = x 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 eeb6cf69cf4..b9ebe4283c1 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 @@ -21098,12 +21098,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } - @TestMetadata("localTypeAlias.kt") - public void testLocalTypeAlias() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/localTypeAlias.kt"); - doTest(fileName); - } - @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt"); diff --git a/js/js.translator/testData/box/inlineMultiModule/typealiases.kt b/js/js.translator/testData/box/inlineMultiModule/typealiases.kt index 11e2983b7c6..6247d0035f8 100644 --- a/js/js.translator/testData/box/inlineMultiModule/typealiases.kt +++ b/js/js.translator/testData/box/inlineMultiModule/typealiases.kt @@ -10,6 +10,7 @@ object O { } class C { + @Suppress("TOPLEVEL_TYPEALIASES_ONLY") typealias B = O }