[LL FIR] KTIJ-24574 Fix containing declaration finder for init blocks
- KTIJ-24574 occurred because a local destructuring declaration was erroneously returned as the non-local containing declaration of an element by `getNonLocalContainingOrThisDeclaration`. This occurred in `init` blocks. KTIJ-24574 fixed
This commit is contained in:
committed by
Space Team
parent
769fb835f9
commit
fb43e53ca3
+19
-14
@@ -18,7 +18,9 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isObjectLiteral
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.psi2ir.deparenthesize
|
||||
|
||||
|
||||
@@ -107,24 +109,27 @@ internal fun PsiElement.getNonLocalContainingOrThisDeclaration(predicate: (KtDec
|
||||
|
||||
for (parent in parentsWithSelf) {
|
||||
if (candidate != null) {
|
||||
if (parent is KtEnumEntry || parent is KtCallableDeclaration) {
|
||||
// Candidate turned to be local. Let's find another one
|
||||
if (parent is KtEnumEntry || parent is KtCallableDeclaration || parent is KtClassInitializer) {
|
||||
// Candidate turned out to be local. Let's find another one.
|
||||
candidate = null
|
||||
}
|
||||
}
|
||||
|
||||
when (parent) {
|
||||
is KtScript -> propose(parent)
|
||||
is KtDestructuringDeclaration -> propose(parent)
|
||||
is KtNamedDeclaration -> {
|
||||
val isKindApplicable = when (parent) {
|
||||
is KtClassOrObject -> !parent.isObjectLiteral()
|
||||
is KtDeclarationWithBody, is KtProperty, is KtTypeAlias -> true
|
||||
else -> false
|
||||
}
|
||||
// A new candidate only needs to be proposed when `candidate` is null.
|
||||
if (candidate == null) {
|
||||
when (parent) {
|
||||
is KtScript -> propose(parent)
|
||||
is KtDestructuringDeclaration -> propose(parent)
|
||||
is KtNamedDeclaration -> {
|
||||
val isKindApplicable = when (parent) {
|
||||
is KtClassOrObject -> !parent.isObjectLiteral()
|
||||
is KtDeclarationWithBody, is KtProperty, is KtTypeAlias -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
if (isKindApplicable && declarationCanBeLazilyResolved(parent) && predicate(parent)) {
|
||||
propose(parent)
|
||||
if (isKindApplicable && declarationCanBeLazilyResolved(parent) && predicate(parent)) {
|
||||
propose(parent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user