From efad248d7d676c00b219034d57f8aef0473bc21c Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Wed, 6 Sep 2023 00:38:25 +0200 Subject: [PATCH] KT-61245 [LL API] Refactor `ContextCollector` Extract visiting class header into a separate function ^KT-61245 Fixed --- .../level/api/fir/util/ContextCollector.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt index 37db7cfb83d..8fd23efaea1 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt @@ -326,13 +326,7 @@ private class ContextCollectorVisitor( regularClass.lazyResolveToPhase(FirResolvePhase.STATUS) context.withContainingClass(regularClass) { - processList(regularClass.contextReceivers) - processList(regularClass.typeParameters) - - // we do it before we actually visit the constructors, - // because we don't want to have implicit this receiver - // for supertype callee positions - processList(regularClass.superTypeRefs) + processClassHeader(regularClass) context.withRegularClass(regularClass, holder) { dumpContext(regularClass, ContextKind.BODY) @@ -351,6 +345,19 @@ private class ContextCollectorVisitor( } } + /** + * Process the parts of the class declaration which resolution is not affected + * by the class own supertypes. + * + * Processing those parts before adding the implicit receiver of the class + * to the [context] allows to not collect incorrect contexts for them later on. + */ + private fun Processor.processClassHeader(regularClass: FirRegularClass) { + processList(regularClass.contextReceivers) + processList(regularClass.typeParameters) + processList(regularClass.superTypeRefs) + } + override fun visitConstructor(constructor: FirConstructor) = withProcessor { dumpContext(constructor, ContextKind.SELF)