KT-25156: Fix stack overflow on top level destructuring with lambda init
Support destructuring in additional resolve pass (resolveToElements) #KT-25156 Fixed
This commit is contained in:
@@ -33,10 +33,7 @@ import org.jetbrains.kotlin.frontend.di.createContainerForBodyResolve
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.CodeFragmentAnalyzer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.lazy.*
|
||||
@@ -256,7 +253,8 @@ class ResolveElementCache(
|
||||
KtTypeConstraint::class.java,
|
||||
KtPackageDirective::class.java,
|
||||
KtCodeFragment::class.java,
|
||||
KtTypeAlias::class.java
|
||||
KtTypeAlias::class.java,
|
||||
KtDestructuringDeclaration::class.java
|
||||
) as KtElement?
|
||||
|
||||
when (elementOfAdditionalResolve) {
|
||||
@@ -314,6 +312,12 @@ class ResolveElementCache(
|
||||
}
|
||||
|
||||
val trace: BindingTrace = when (resolveElement) {
|
||||
is KtDestructuringDeclaration -> destructuringDeclarationAdditionalResolve(
|
||||
resolveSession,
|
||||
resolveElement,
|
||||
bodyResolveMode.bindingTraceFilter
|
||||
)
|
||||
|
||||
is KtNamedFunction -> functionAdditionalResolve(
|
||||
resolveSession,
|
||||
resolveElement,
|
||||
@@ -535,6 +539,21 @@ class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
|
||||
private fun destructuringDeclarationAdditionalResolve(
|
||||
resolveSession: ResolveSession,
|
||||
declaration: KtDestructuringDeclaration,
|
||||
bindingTraceFilter: BindingTraceFilter
|
||||
): BindingTrace {
|
||||
for (entry in declaration.entries) {
|
||||
val descriptor = resolveSession.resolveToDescriptor(entry) as PropertyDescriptor
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor)
|
||||
forceResolveAnnotationsInside(entry)
|
||||
}
|
||||
|
||||
return createDelegatingTrace(declaration, bindingTraceFilter)
|
||||
}
|
||||
|
||||
private fun propertyAdditionalResolve(
|
||||
resolveSession: ResolveSession, property: KtProperty,
|
||||
file: KtFile,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
val <error descr="Destructuring declarations are only allowed for local variables/values">(a, b)</error> by <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">lazy</error> { <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">Pair</error>(1, 2) }
|
||||
val <error descr="Destructuring declarations are only allowed for local variables/values">(c, d)</error> = <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">run</error> { <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">Pair</error>(3, 4) }
|
||||
|
||||
|
||||
class Foo {
|
||||
val <error descr="Destructuring declarations are only allowed for local variables/values">(a, b)</error> by <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">lazy</error> { <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">Pair</error>(1, 2) }
|
||||
val <error descr="Destructuring declarations are only allowed for local variables/values">(c, d)</error> = <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">run</error> { <error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved">Pair</error>(3, 4) }
|
||||
}
|
||||
|
||||
// NO_CHECK_INFOS
|
||||
// WITH_RUNTIME
|
||||
+5
@@ -114,6 +114,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
runTest("idea/testData/highlighter/Todo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelDestructuring.kt")
|
||||
public void testTopLevelDestructuring() throws Exception {
|
||||
runTest("idea/testData/highlighter/TopLevelDestructuring.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelOpenSuspendFun.kt")
|
||||
public void testTopLevelOpenSuspendFun() throws Exception {
|
||||
runTest("idea/testData/highlighter/TopLevelOpenSuspendFun.kt");
|
||||
|
||||
Reference in New Issue
Block a user