From 1d5ade11668a48de5a6b25881698ed95926ee216 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 3 Aug 2023 16:01:25 +0200 Subject: [PATCH] K2: minor, remove misleading FirMemberDeclaration.containerSource "Container source" means "the source of the container". So, if you called this extension on a class (`FirClassLikeDeclaration`), it was reasonable to assume that you would get the source of its _containing class_, whereas the function actually returned the source of the class itself. Instead of inventing another name for this function, I've decided to inline and remove it because it has only one usage. --- .../fir/declarations/utils/declarationAttributes.kt | 6 ------ .../kotlin/backend/konan/descriptors/utils.kt | 11 ++++++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/declarationAttributes.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/declarationAttributes.kt index 82e572fd9a0..ccd8fca2df1 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/declarationAttributes.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/declarationAttributes.kt @@ -49,12 +49,6 @@ var T.danglingTypeConstraints: List? // ----------------------------------- Utils ----------------------------------- -val FirMemberDeclaration.containerSource: SourceElement? - get() = when (this) { - is FirCallableDeclaration -> containerSource - is FirClassLikeDeclaration -> sourceElement - } - val FirProperty.hasExplicitBackingField: Boolean get() = backingField != null && backingField !is FirDefaultPropertyBackingField diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt index ba3def3a272..c5570a68489 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt @@ -7,8 +7,10 @@ package org.jetbrains.kotlin.backend.konan.descriptors import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl +import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration +import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration -import org.jetbrains.kotlin.fir.declarations.utils.containerSource +import org.jetbrains.kotlin.fir.declarations.utils.sourceElement import org.jetbrains.kotlin.fir.lazy.AbstractFir2IrLazyDeclaration import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction @@ -62,8 +64,11 @@ private fun DeclarationDescriptor.isFromFirDeserializedInteropLibrary(): Boolean // - K2 metadata deserializer doesn't set containerSource for property accessors. val topLevelDeclaration = declaration.findTopLevelDeclaration().propertyIfAccessor() - val firDeclaration = (topLevelDeclaration as? AbstractFir2IrLazyDeclaration<*>)?.fir ?: return false - val containerSource = (firDeclaration as? FirMemberDeclaration)?.containerSource + val firDeclaration = (topLevelDeclaration as? AbstractFir2IrLazyDeclaration<*>)?.fir as? FirMemberDeclaration ?: return false + val containerSource = when (firDeclaration) { + is FirCallableDeclaration -> firDeclaration.containerSource + is FirClassLikeDeclaration -> firDeclaration.sourceElement + } return containerSource is KlibDeserializedContainerSource && containerSource.isFromNativeInteropLibrary }