From 9047ddfc2fbdebb5f804ff3dc9992bb7d84d71d8 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Wed, 10 Jul 2019 15:41:29 +0300 Subject: [PATCH] [API Usage] Refine supertypes when getting content of member scope --- .../lazy/descriptors/LazyClassMemberScope.kt | 15 ++++++++++----- .../descriptors/DeserializedClassDescriptor.kt | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) 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 c6d89ee41d9..7c8d55eef35 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 @@ -76,7 +76,7 @@ open class LazyClassMemberScope( protected open fun computeExtraDescriptors(location: LookupLocation): Collection { val result = ArrayList() - for (supertype in thisDescriptor.typeConstructor.supertypes) { + for (supertype in supertypes) { for (descriptor in supertype.memberScope.getContributedDescriptors()) { if (descriptor is FunctionDescriptor) { result.addAll(getContributedFunctions(descriptor.name, location)) @@ -96,11 +96,16 @@ open class LazyClassMemberScope( return result } + val supertypes by storageManager.createLazyValue { + @UseExperimental(TypeRefinement::class) + kotlinTypeRefiner.refineSupertypes(thisDescriptor) + } + private val _variableNames: MutableSet by lazy(LazyThreadSafetyMode.PUBLICATION) { mutableSetOf().apply { addAll(declarationProvider.getDeclarationNames()) - thisDescriptor.typeConstructor.supertypes.flatMapTo(this) { + supertypes.flatMapTo(this) { it.memberScope.getVariableNames() } } @@ -110,7 +115,7 @@ open class LazyClassMemberScope( by lazy(LazyThreadSafetyMode.PUBLICATION) { mutableSetOf().apply { addAll(declarationProvider.getDeclarationNames()) - thisDescriptor.typeConstructor.supertypes.flatMapTo(this) { + supertypes.flatMapTo(this) { it.memberScope.getFunctionNames() } @@ -203,7 +208,7 @@ open class LazyClassMemberScope( val location = NoLookupLocation.FOR_ALREADY_TRACKED val fromSupertypes = arrayListOf() - for (supertype in thisDescriptor.typeConstructor.supertypes) { + for (supertype in supertypes) { fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, location)) } result.addAll(generateDelegatingDescriptors(name, EXTRACT_FUNCTIONS, result)) @@ -345,7 +350,7 @@ open class LazyClassMemberScope( // Members from supertypes val fromSupertypes = ArrayList() - for (supertype in thisDescriptor.typeConstructor.supertypes) { + for (supertype in supertypes) { fromSupertypes.addAll(supertype.memberScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED)) } result.addAll(generateDelegatingDescriptors(name, EXTRACT_PROPERTIES, result)) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt index be3d7e34718..8543071fa8d 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt @@ -217,6 +217,11 @@ class DeserializedClassDescriptor( computeDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) } + private val refinedSupertypes = c.storageManager.createLazyValue { + @UseExperimental(TypeRefinement::class) + kotlinTypeRefiner.refineSupertypes(classDescriptor) + } + override fun getContributedDescriptors( kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean ): Collection = allDescriptors() @@ -233,7 +238,7 @@ class DeserializedClassDescriptor( override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection) { val fromSupertypes = ArrayList() - for (supertype in classDescriptor.getTypeConstructor().supertypes) { + for (supertype in refinedSupertypes()) { fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)) } @@ -247,7 +252,7 @@ class DeserializedClassDescriptor( override fun computeNonDeclaredProperties(name: Name, descriptors: MutableCollection) { val fromSupertypes = ArrayList() - for (supertype in classDescriptor.getTypeConstructor().supertypes) { + for (supertype in refinedSupertypes()) { fromSupertypes.addAll(supertype.memberScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED)) } generateFakeOverrides(name, fromSupertypes, descriptors)