From 5bf8b4d946ce1fc29ce2f872effd84d9da0bf8c9 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 8 Dec 2015 20:57:45 +0300 Subject: [PATCH] Allow to use "static" part of class in own constructors by short name, including in primary constructor --- .../ClassDescriptorWithResolutionScopes.java | 3 + .../kotlin/resolve/BodyResolver.java | 8 +-- .../ClassResolutionScopesSupport.kt | 34 ++++++--- .../lazy/descriptors/LazyClassDescriptor.java | 6 ++ .../lazy/descriptors/LazyClassMemberScope.kt | 7 +- .../jetbrains/kotlin/resolve/scopes/Scopes.kt | 3 +- .../kotlin/resolve/scopes/utils/ScopeUtils.kt | 29 ++++++++ .../scopes/classHeader/annotationOnClass.kt | 51 +++++++++++++ .../scopes/classHeader/annotationOnClass.txt | 71 ++++++++++++++++++ .../classHeader/annotationOnConstructors.kt | 65 +++++++++++++++++ .../classHeader/annotationOnConstructors.txt | 72 +++++++++++++++++++ .../classHeader/classGenericParameters.kt | 20 ++++++ .../classHeader/classGenericParameters.txt | 55 ++++++++++++++ .../tests/scopes/classHeader/classParents.kt | 12 ++++ .../tests/scopes/classHeader/classParents.txt | 34 +++++++++ .../tests/scopes/classHeader/constructors.kt | 65 +++++++++++++++++ .../tests/scopes/classHeader/constructors.txt | 56 +++++++++++++++ .../tests/scopes/classHeader/delegation.kt | 50 +++++++++++++ .../tests/scopes/classHeader/delegation.txt | 68 ++++++++++++++++++ .../scopes/classHeader/simpleDelegation.kt | 10 +++ .../scopes/classHeader/simpleDelegation.txt | 22 ++++++ .../classHeader/superConstructorArguments.kt | 48 +++++++++++++ .../classHeader/superConstructorArguments.txt | 62 ++++++++++++++++ ...structorArgumentsInSecondaryConstructor.kt | 50 +++++++++++++ ...tructorArgumentsInSecondaryConstructor.txt | 62 ++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 63 ++++++++++++++++ .../idea/project/ResolveElementCache.kt | 6 +- .../ValInConstructorParameter4.kt.after | 2 +- .../NestedClassReferenceOutsideClassBody.kt | 4 +- ...tedClassReferenceOutsideClassBody.kt.after | 4 +- 30 files changed, 1017 insertions(+), 25 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classParents.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/classParents.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/constructors.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/constructors.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/delegation.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.txt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.kt create mode 100644 compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/descriptors/ClassDescriptorWithResolutionScopes.java b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/ClassDescriptorWithResolutionScopes.java index 801e1728076..91913c2e728 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/descriptors/ClassDescriptorWithResolutionScopes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/ClassDescriptorWithResolutionScopes.java @@ -27,6 +27,9 @@ public interface ClassDescriptorWithResolutionScopes extends ClassDescriptor { @NotNull LexicalScope getScopeForClassHeaderResolution(); + @NotNull + LexicalScope getScopeForConstructorHeaderResolution(); + @NotNull LexicalScope getScopeForMemberDeclarationResolution(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 784759efae7..2156e2a8c31 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -239,7 +239,7 @@ public class BodyResolver { resolveDelegationSpecifierList(c.getOuterDataFlowInfo(), classOrObject, descriptor, descriptor.getUnsubstitutedPrimaryConstructor(), - descriptor.getScopeForClassHeaderResolution(), + descriptor.getScopeForConstructorHeaderResolution(), descriptor.getScopeForMemberDeclarationResolution()); } } @@ -249,13 +249,13 @@ public class BodyResolver { @NotNull KtClassOrObject jetClass, @NotNull final ClassDescriptor descriptor, @Nullable final ConstructorDescriptor primaryConstructor, - @NotNull LexicalScope scopeForSupertypeResolution, + @NotNull LexicalScope scopeForConstructorResolution, @NotNull final LexicalScope scopeForMemberResolution ) { final LexicalScope scopeForConstructor = primaryConstructor == null ? null - : FunctionDescriptorUtil.getFunctionInnerScope(scopeForSupertypeResolution, primaryConstructor, trace); + : FunctionDescriptorUtil.getFunctionInnerScope(scopeForConstructorResolution, primaryConstructor, trace); final ExpressionTypingServices typeInferrer = expressionTypingServices; // TODO : flow final Map supertypes = Maps.newLinkedHashMap(); @@ -556,7 +556,7 @@ public class BodyResolver { if (unsubstitutedPrimaryConstructor != null) { ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations()); - LexicalScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForClassHeaderResolution(), + LexicalScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForConstructorHeaderResolution(), unsubstitutedPrimaryConstructor); valueParameterResolver.resolveValueParameters(klass.getPrimaryConstructorParameters(), unsubstitutedPrimaryConstructor.getValueParameters(), diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt index a8f5c2320af..fa7aade7277 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny import org.jetbrains.kotlin.resolve.scopes.* +import org.jetbrains.kotlin.resolve.scopes.utils.ThrowingLexicalScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* @@ -42,13 +43,17 @@ class ClassResolutionScopesSupport( scopeWithGenerics(getOuterScope()) } + public val scopeForConstructorHeaderResolution: () -> LexicalScope = storageManager.createLazyValue { + scopeWithGenerics(scopeForStaticMemberDeclarationResolution()) + } + private val inheritanceScope: () -> LexicalScope = storageManager.createLazyValueWithPostCompute( { classDescriptor.getAllSuperclassesAndMeWithoutAny().asReversed().fold(getOuterScope()) { scope, currentClass -> createInheritanceScope(parent = scope, ownerDescriptor = classDescriptor, classDescriptor = currentClass) } }, - { createInheritanceScope(getOuterScope(), classDescriptor, classDescriptor) }, + createThrowingLexicalScope, {} ) @@ -59,15 +64,19 @@ class ClassResolutionScopesSupport( LexicalScopeKind.CLASS_MEMBER_SCOPE) } - public val scopeForStaticMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValue { - if (classDescriptor.kind.isSingleton) { - scopeForMemberDeclarationResolution() - } - else { - LexicalScopeImpl(inheritanceScope(), classDescriptor, false, null, - LexicalScopeKind.CLASS_STATIC_SCOPE) - } - } + public val scopeForStaticMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValueWithPostCompute( + { + if (classDescriptor.kind.isSingleton) { + scopeForMemberDeclarationResolution() + } + else { + LexicalScopeImpl(inheritanceScope(), classDescriptor, false, null, + LexicalScopeKind.CLASS_STATIC_SCOPE) + } + }, + createThrowingLexicalScope, + {} + ) public val scopeForInitializerResolution: () -> LexicalScope = storageManager.createLazyValue { val primaryConstructor = classDescriptor.unsubstitutedPrimaryConstructor ?: @@ -118,4 +127,7 @@ class ClassResolutionScopesSupport( memberScopes = *staticScopes.toTypedArray(), isStaticScope = true) } -} \ No newline at end of file + companion object { + private val createThrowingLexicalScope: (Boolean) -> LexicalScope = { ThrowingLexicalScope() } + } +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java index 0624cf3acee..9656ef60529 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -292,6 +292,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes return resolutionScopesSupport.getScopeForClassHeaderResolution().invoke(); } + @Override + @NotNull + public LexicalScope getScopeForConstructorHeaderResolution() { + return resolutionScopesSupport.getScopeForConstructorHeaderResolution().invoke(); + } + @Override @NotNull public LexicalScope getScopeForMemberDeclarationResolution() { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt index 796c29ff850..759a0bc12f8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt @@ -221,7 +221,8 @@ public open class LazyClassMemberScope( val parameter = primaryConstructorParameters.get(valueParameterDescriptor.index) if (parameter.hasValOrVar()) { val propertyDescriptor = c.descriptorResolver.resolvePrimaryConstructorParameterToAProperty( - thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution(), parameter, trace) + // TODO: can't test because we get types from cache for this case + thisDescriptor, valueParameterDescriptor, thisDescriptor.scopeForConstructorHeaderResolution, parameter, trace) result.add(propertyDescriptor) } } @@ -281,7 +282,7 @@ public open class LazyClassMemberScope( if (DescriptorUtils.canHaveDeclaredConstructors(thisDescriptor) || hasPrimaryConstructor) { val constructor = c.functionDescriptorResolver.resolvePrimaryConstructorDescriptor( - thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace) + thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor, classOrObject, trace) constructor ?: return null setDeferredReturnType(constructor) return constructor @@ -298,7 +299,7 @@ public open class LazyClassMemberScope( return classOrObject.getSecondaryConstructors().map { constructor -> val descriptor = c.functionDescriptorResolver.resolveSecondaryConstructorDescriptor( - thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, constructor, trace + thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor, constructor, trace ) setDeferredReturnType(descriptor) descriptor diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt index fedcade1b68..528a261b0cf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -55,6 +55,7 @@ interface LexicalScope: HierarchicalScope { enum class LexicalScopeKind(val withLocalDescriptors: Boolean) { EMPTY(false), + THROWING(false), CLASS_HEADER(false), CLASS_INHERITANCE(false), @@ -147,4 +148,4 @@ abstract class BaseImportingScope(parent: ImportingScope?) : BaseHierarchicalSco override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection = emptyList() override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection = emptyList() -} \ No newline at end of file +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt index 6a6ece07dfc..35e317342ba 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt @@ -245,3 +245,32 @@ fun chainImportingScopes(scopes: List, tail: ImportingScope? = n scope.withParent(current) } } + +class ThrowingLexicalScope : LexicalScope { + override val parent: HierarchicalScope + get() = throw IllegalStateException() + + override val ownerDescriptor: DeclarationDescriptor + get() = throw IllegalStateException() + override val isOwnerDescriptorAccessibleByLabel: Boolean + get() = throw IllegalStateException() + override val implicitReceiver: ReceiverParameterDescriptor? + get() = throw IllegalStateException() + override val kind: LexicalScopeKind + get() = LexicalScopeKind.THROWING + + override fun printStructure(p: Printer) = + throw IllegalStateException() + + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = + throw IllegalStateException() + + override fun getContributedVariables(name: Name, location: LookupLocation): Collection = + throw IllegalStateException() + + override fun getContributedFunctions(name: Name, location: LookupLocation): Collection = + throw IllegalStateException() + + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection = + throw IllegalStateException() +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.kt new file mode 100644 index 00000000000..223bc643814 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +annotation class Ann( + val kc1: KClass<*>, + val kc2: KClass<*>, + val kc3: KClass<*>, + val c: Int, + val cc: Int, + val cn: Int, + val ci: Int, + val t1: Int, + val t2: Int +) + +@Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) +class A { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.txt new file mode 100644 index 00000000000..0744f170b29 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.txt @@ -0,0 +1,71 @@ +package + +@Ann() public final class A { + public constructor A() + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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 annotation class Ann : kotlin.Annotation { + public constructor Ann(/*0*/ kc1: kotlin.reflect.KClass<*>, /*1*/ kc2: kotlin.reflect.KClass<*>, /*2*/ kc3: kotlin.reflect.KClass<*>, /*3*/ c: kotlin.Int, /*4*/ cc: kotlin.Int, /*5*/ cn: kotlin.Int, /*6*/ ci: kotlin.Int, /*7*/ t1: kotlin.Int, /*8*/ t2: kotlin.Int) + public final val c: kotlin.Int + public final val cc: kotlin.Int + public final val ci: kotlin.Int + public final val cn: kotlin.Int + public final val kc1: kotlin.reflect.KClass<*> + public final val kc2: kotlin.reflect.KClass<*> + public final val kc3: kotlin.reflect.KClass<*> + public final val t1: kotlin.Int + public final val t2: kotlin.Int + 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/scopes/classHeader/annotationOnConstructors.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.kt new file mode 100644 index 00000000000..8daa7e48d27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.* + +annotation class Ann( + val kc1: KClass<*>, + val kc2: KClass<*>, + val kc3: KClass<*>, + val c: Int, + val cc: Int, + val cn: Int, + val ci: Int, + val t1: Int, + val t2: Int +) + +class A +@Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) +constructor() { + + @Ann( + Nested::class, + Inner::class, + Interface::class, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + constructor(dummy: Int) : this() + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.txt new file mode 100644 index 00000000000..d77ab6e50de --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.txt @@ -0,0 +1,72 @@ +package + +public final class A { + @Ann(c = 1, cc = 1, ci = 3, cn = 2, kc1 = A.Nested::class, kc2 = A.Inner::class, kc3 = A.Interface::class) public constructor A() + @Ann(c = 1, cc = 1, ci = 3, cn = 2, kc1 = A.Nested::class, kc2 = A.Inner::class, kc3 = A.Interface::class) public constructor A(/*0*/ dummy: kotlin.Int) + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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 annotation class Ann : kotlin.Annotation { + public constructor Ann(/*0*/ kc1: kotlin.reflect.KClass<*>, /*1*/ kc2: kotlin.reflect.KClass<*>, /*2*/ kc3: kotlin.reflect.KClass<*>, /*3*/ c: kotlin.Int, /*4*/ cc: kotlin.Int, /*5*/ cn: kotlin.Int, /*6*/ ci: kotlin.Int, /*7*/ t1: kotlin.Int, /*8*/ t2: kotlin.Int) + public final val c: kotlin.Int + public final val cc: kotlin.Int + public final val ci: kotlin.Int + public final val cn: kotlin.Int + public final val kc1: kotlin.reflect.KClass<*> + public final val kc2: kotlin.reflect.KClass<*> + public final val kc3: kotlin.reflect.KClass<*> + public final val t1: kotlin.Int + public final val t2: kotlin.Int + 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/scopes/classHeader/classGenericParameters.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.kt new file mode 100644 index 00000000000..96564d35835 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.kt @@ -0,0 +1,20 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class ANested, F: Inner, G: Interace> { + + class Nested + + inner class Inner + + interface Interface +} + +class B where T : Nested, F: Inner, G: Interace { + + class Nested + + inner class Inner + + interface Interface +} + diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt new file mode 100644 index 00000000000..0a32fe8edd5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.txt @@ -0,0 +1,55 @@ +package + +public final class A { + public constructor 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 final inner class Inner /*captured type parameters: /*0*/ T : [ERROR : Nested], /*1*/ F : [ERROR : Inner], /*2*/ G : [ERROR : Interace]*/ { + public constructor Inner() + 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 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 + } + + public final class Nested { + public constructor Nested() + 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 B { + public constructor B() + 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 inner class Inner /*captured type parameters: /*0*/ T : [ERROR : Nested], /*1*/ F : [ERROR : Inner], /*2*/ G : [ERROR : Interace]*/ { + public constructor Inner() + 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 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 + } + + public final class Nested { + public constructor Nested() + 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/scopes/classHeader/classParents.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.kt new file mode 100644 index 00000000000..9ccebc9d19b --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +class A(impl: Interface) : Nested(), Interface by impl, Inner, I<Nested, Interface, Inner> { + + class Nested + + inner class Inner + + interface Interface +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.txt new file mode 100644 index 00000000000..10b4fa08ef1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/classParents.txt @@ -0,0 +1,34 @@ +package + +public final class A : I<[ERROR : Nested], [ERROR : Interface], [ERROR : Inner]> { + public constructor A(/*0*/ impl: A.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 + + public final inner class Inner { + public constructor Inner() + 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 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 + } + + public final class Nested { + public constructor Nested() + 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 interface I { + 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/scopes/classHeader/constructors.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.kt new file mode 100644 index 00000000000..27b65294ae5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A( + n: Nested = foo(), + n2: Nested = Nested(), + inn: Inner = null!!, + inn2: Inner = Inner(), + i: Interface = null!!, + c: Int = CONST, + cc: Int = Companion.CONST, + cn: Int = Nested.CONST, + ci: Int = Interface.CONST, + t1: Int = a, + t2: Int = b() +) { + + constructor( + dummy: Int, + n: Nested = foo(), + n2: Nested = Nested(), + inn: Inner = null!!, + inn2: Inner = Inner(), + i: Interface = null!!, + c: Int = CONST, + cc: Int = Companion.CONST, + cn: Int = Nested.CONST, + ci: Int = Interface.CONST, + t1: Int = a, + t2: Int = b() + ) : this( + foo(), + Nested(), + inn, + Inner(), + i, + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.txt new file mode 100644 index 00000000000..e91e93d635d --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.txt @@ -0,0 +1,56 @@ +package + +public final class A { + public constructor A(/*0*/ n: A.Nested = ..., /*1*/ n2: A.Nested = ..., /*2*/ inn: A.Inner = ..., /*3*/ inn2: A.Inner = ..., /*4*/ i: A.Interface = ..., /*5*/ c: kotlin.Int = ..., /*6*/ cc: kotlin.Int = ..., /*7*/ cn: kotlin.Int = ..., /*8*/ ci: kotlin.Int = ..., /*9*/ t1: kotlin.Int = ..., /*10*/ t2: kotlin.Int = ...) + public constructor A(/*0*/ dummy: kotlin.Int, /*1*/ n: A.Nested = ..., /*2*/ n2: A.Nested = ..., /*3*/ inn: A.Inner = ..., /*4*/ inn2: A.Inner = ..., /*5*/ i: A.Interface = ..., /*6*/ c: kotlin.Int = ..., /*7*/ cc: kotlin.Int = ..., /*8*/ cn: kotlin.Int = ..., /*9*/ ci: kotlin.Int = ..., /*10*/ t1: kotlin.Int = ..., /*11*/ t2: kotlin.Int = ...) + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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/scopes/classHeader/delegation.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt new file mode 100644 index 00000000000..f89c11c2cff --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) : I + +class A : I by S( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.txt new file mode 100644 index 00000000000..967c7c664c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/delegation.txt @@ -0,0 +1,68 @@ +package + +public final class A : I { + public constructor A() + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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 interface I { + 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 open class S : I { + public constructor S(/*0*/ n: A.Nested, /*1*/ n2: A.Nested, /*2*/ inn: A.Inner, /*3*/ c: kotlin.Int, /*4*/ cc: kotlin.Int, /*5*/ cn: kotlin.Int, /*6*/ ci: kotlin.Int, /*7*/ t1: kotlin.Int, /*8*/ t2: kotlin.Int) + 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/scopes/classHeader/simpleDelegation.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.kt new file mode 100644 index 00000000000..255ac8e7eb9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface I + +class A : I by impl { + + companion object { + val impl = object : I {} + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.txt new file mode 100644 index 00000000000..983484fc53f --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.txt @@ -0,0 +1,22 @@ +package + +public final class A : I { + public constructor 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 companion object Companion { + private constructor Companion() + public final val impl: I + 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 interface I { + 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/scopes/classHeader/superConstructorArguments.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt new file mode 100644 index 00000000000..e8d6d6d37d2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt @@ -0,0 +1,48 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) + +class A : S ( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() +) { + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.txt new file mode 100644 index 00000000000..c0ab5449d7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.txt @@ -0,0 +1,62 @@ +package + +public final class A : S { + public constructor A() + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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 open class S { + public constructor S(/*0*/ n: A.Nested, /*1*/ n2: A.Nested, /*2*/ inn: A.Inner, /*3*/ c: kotlin.Int, /*4*/ cc: kotlin.Int, /*5*/ cn: kotlin.Int, /*6*/ ci: kotlin.Int, /*7*/ t1: kotlin.Int, /*8*/ t2: kotlin.Int) + 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/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.kt new file mode 100644 index 00000000000..223d40e1cd1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class S( + n: A.Nested, + n2: A.Nested, + inn: A.Inner, + c: Int, + cc: Int, + cn: Int, + ci: Int, + t1: Int, + t2: Int +) + +class A : S { + + constructor() : super( + foo(), + Nested(), + Inner(), + CONST, + Companion.CONST, + Nested.CONST, + Interface.CONST, + a, + b() + ) + + class Nested { + companion object { + const val CONST = 2 + } + } + + inner class Inner + + interface Interface { + companion object { + const val CONST = 3 + } + } + + val a = 1 + fun b() = 2 + + companion object { + const val CONST = 1 + fun foo(): Nested = null!! + } +} diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.txt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.txt new file mode 100644 index 00000000000..c0ab5449d7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.txt @@ -0,0 +1,62 @@ +package + +public final class A : S { + public constructor A() + public final val a: kotlin.Int = 1 + public final fun b(): kotlin.Int + 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 const final val CONST: kotlin.Int = 1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): A.Nested + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final inner class Inner { + public constructor Inner() + 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 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 + + public companion object Companion { + private constructor Companion() + public const final val CONST: kotlin.Int = 3 + 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 Nested { + public constructor Nested() + 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 const final val CONST: kotlin.Int = 2 + 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 open class S { + public constructor S(/*0*/ n: A.Nested, /*1*/ n2: A.Nested, /*2*/ inn: A.Inner, /*3*/ c: kotlin.Int, /*4*/ cc: kotlin.Int, /*5*/ cn: kotlin.Int, /*6*/ ci: kotlin.Int, /*7*/ t1: kotlin.Int, /*8*/ t2: kotlin.Int) + 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 4ce0faf7239..027205c7f01 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13905,6 +13905,69 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("compiler/testData/diagnostics/tests/scopes/classHeader") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ClassHeader extends AbstractDiagnosticsTest { + public void testAllFilesPresentInClassHeader() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/scopes/classHeader"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("annotationOnClass.kt") + public void testAnnotationOnClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnClass.kt"); + doTest(fileName); + } + + @TestMetadata("annotationOnConstructors.kt") + public void testAnnotationOnConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/annotationOnConstructors.kt"); + doTest(fileName); + } + + @TestMetadata("classGenericParameters.kt") + public void testClassGenericParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/classGenericParameters.kt"); + doTest(fileName); + } + + @TestMetadata("classParents.kt") + public void testClassParents() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/classParents.kt"); + doTest(fileName); + } + + @TestMetadata("constructors.kt") + public void testConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/constructors.kt"); + doTest(fileName); + } + + @TestMetadata("delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/delegation.kt"); + doTest(fileName); + } + + @TestMetadata("simpleDelegation.kt") + public void testSimpleDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/simpleDelegation.kt"); + doTest(fileName); + } + + @TestMetadata("superConstructorArguments.kt") + public void testSuperConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("superConstructorArgumentsInSecondaryConstructor.kt") + public void testSuperConstructorArgumentsInSecondaryConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/tests/scopes/inheritance") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt index cbb4f101342..b6da0b6405e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt @@ -404,9 +404,9 @@ public class ResolveElementCache( bodyResolver.resolveDelegationSpecifierList(DataFlowInfo.EMPTY, classOrObject, descriptor, - descriptor.getUnsubstitutedPrimaryConstructor(), - descriptor.getScopeForClassHeaderResolution(), - descriptor.getScopeForMemberDeclarationResolution()) + descriptor.unsubstitutedPrimaryConstructor, + descriptor.scopeForConstructorHeaderResolution, + descriptor.scopeForMemberDeclarationResolution) return trace } diff --git a/idea/idea-completion/testData/handlers/basic/override/ValInConstructorParameter4.kt.after b/idea/idea-completion/testData/handlers/basic/override/ValInConstructorParameter4.kt.after index 6e5d28e85f6..fd5a7a0325a 100644 --- a/idea/idea-completion/testData/handlers/basic/override/ValInConstructorParameter4.kt.after +++ b/idea/idea-completion/testData/handlers/basic/override/ValInConstructorParameter4.kt.after @@ -4,7 +4,7 @@ interface I { val p: CCCC.Nested } -class CCCC(override val p: CCCC.Nestedval x: Int) : I { +class CCCC(override val p: Nestedval x: Int) : I { interface Nested } diff --git a/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt b/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt index 08bf4f8d2a9..617a6ae0f96 100644 --- a/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt +++ b/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt @@ -2,6 +2,8 @@ package ppp import ppp.Base.Nested -class Base(p: Nested) { +fun foo(p: Nested) {} + +class Base { class Nested } diff --git a/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt.after b/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt.after index 08bf4f8d2a9..617a6ae0f96 100644 --- a/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt.after +++ b/idea/testData/editor/optimizeImports/NestedClassReferenceOutsideClassBody.kt.after @@ -2,6 +2,8 @@ package ppp import ppp.Base.Nested -class Base(p: Nested) { +fun foo(p: Nested) {} + +class Base { class Nested }