[FIR] make script destructuring declaration entry initializer lazy expression
This change is required to properly support such declarations in lazy resolution mode as we usually replaced initializers with lazy expressions during the body calculation phase ^KT-62840
This commit is contained in:
committed by
Space Team
parent
c0f4f7fefd
commit
312feb3dca
+33
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
|
|||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.builder.BodyBuildingMode
|
import org.jetbrains.kotlin.fir.builder.BodyBuildingMode
|
||||||
import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder
|
import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder
|
||||||
|
import org.jetbrains.kotlin.fir.builder.buildDestructuringVariable
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||||
@@ -27,12 +28,15 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||||
import org.jetbrains.kotlin.name.NameUtils
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
import org.jetbrains.kotlin.psi
|
import org.jetbrains.kotlin.psi
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||||
import org.jetbrains.kotlin.util.PrivateForInline
|
import org.jetbrains.kotlin.util.PrivateForInline
|
||||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||||
|
import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
||||||
|
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||||
|
|
||||||
internal class RawFirNonLocalDeclarationBuilder private constructor(
|
internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
@@ -159,6 +163,34 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun convertDestructuringDeclarationEntry(element: KtDestructuringDeclarationEntry): FirVariable {
|
||||||
|
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
||||||
|
requireIsInstance<KtDestructuringDeclarationEntry>(replacementDeclaration)
|
||||||
|
requireIsInstance<FirProperty>(originalDeclaration)
|
||||||
|
|
||||||
|
val container = originalDeclaration.destructuringDeclarationContainerVariable?.fir
|
||||||
|
requireWithAttachment(container != null, { "Container is not found"}) {
|
||||||
|
withFirEntry("originalDeclaration", originalDeclaration)
|
||||||
|
withPsiEntry("element", element)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildDestructuringVariable(
|
||||||
|
moduleData = baseModuleData,
|
||||||
|
container = container,
|
||||||
|
element,
|
||||||
|
isVar = false,
|
||||||
|
localEntries = false,
|
||||||
|
index = element.index(),
|
||||||
|
configure = { configureScriptDestructuringDeclarationEntry(it, container) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtDestructuringDeclarationEntry.index(): Int {
|
||||||
|
val destructuringDeclaration = parent
|
||||||
|
requireIsInstance<KtDestructuringDeclaration>(destructuringDeclaration)
|
||||||
|
return destructuringDeclaration.entries.indexOf(this)
|
||||||
|
}
|
||||||
|
|
||||||
fun convertAnonymousInitializer(element: KtAnonymousInitializer, containingDeclaration: FirDeclaration?): FirAnonymousInitializer {
|
fun convertAnonymousInitializer(element: KtAnonymousInitializer, containingDeclaration: FirDeclaration?): FirAnonymousInitializer {
|
||||||
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
val replacementDeclaration = replacementApplier?.tryReplace(element) ?: element
|
||||||
requireIsInstance<KtAnonymousInitializer>(replacementDeclaration)
|
requireIsInstance<KtAnonymousInitializer>(replacementDeclaration)
|
||||||
@@ -356,6 +388,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is KtDestructuringDeclaration -> visitor.convertDestructuringDeclaration(declarationToBuild, containingDeclaration)
|
is KtDestructuringDeclaration -> visitor.convertDestructuringDeclaration(declarationToBuild, containingDeclaration)
|
||||||
|
is KtDestructuringDeclarationEntry -> visitor.convertDestructuringDeclarationEntry(declarationToBuild)
|
||||||
is KtCodeFragment -> {
|
is KtCodeFragment -> {
|
||||||
val firFile = visitor.convertElement(declarationToBuild, originalDeclaration) as FirFile
|
val firFile = visitor.convertElement(declarationToBuild, originalDeclaration) as FirFile
|
||||||
firFile.codeFragment
|
firFile.codeFragment
|
||||||
|
|||||||
+2
-2
@@ -44,7 +44,7 @@ FILE: [ResolvedTo(IMPORTS)] destructuringAnnotation.kts
|
|||||||
}
|
}
|
||||||
|
|
||||||
@R|DestrAnno|[Types](s = <strcat>(String(destr 1 ), R|/prop|)) [ResolvedTo(ANNOTATION_ARGUMENTS)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: R|MyPair| = R|/MyPair.MyPair|(Int(1), Int(2))
|
@R|DestrAnno|[Types](s = <strcat>(String(destr 1 ), R|/prop|)) [ResolvedTo(ANNOTATION_ARGUMENTS)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: R|MyPair| = R|/MyPair.MyPair|(Int(1), Int(2))
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val a: <implicit> = R|<local>/<destruct>|.component1#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val a: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val b: <implicit> = R|<local>/<destruct>|.component2#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val b: <implicit> = LAZY_EXPRESSION
|
||||||
Vendored
+2
-2
@@ -12,7 +12,7 @@ FILE: [ResolvedTo(IMPORTS)] destructionWithNoRValueScript.kts
|
|||||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
[ResolvedTo(BODY_RESOLVE)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: <ERROR TYPE REF: Initializer required for destructuring declaration> = ERROR_EXPR(Initializer required for destructuring declaration)
|
[ResolvedTo(BODY_RESOLVE)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: <ERROR TYPE REF: Initializer required for destructuring declaration> = ERROR_EXPR(Initializer required for destructuring declaration)
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val o: <implicit> = R|<local>/<destruct>|.component1#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val o: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val r: <implicit> = R|<local>/<destruct>|.component2#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val r: <implicit> = LAZY_EXPRESSION
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ FILE: [ResolvedTo(IMPORTS)] destructuringScript.kts
|
|||||||
public [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] get(): R|kotlin/Pair<kotlin/Int, kotlin/Int>|
|
public [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] get(): R|kotlin/Pair<kotlin/Int, kotlin/Int>|
|
||||||
|
|
||||||
[ResolvedTo(BODY_RESOLVE)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: R|kotlin/Pair<kotlin/Int, kotlin/Int>| = R|/pair|
|
[ResolvedTo(BODY_RESOLVE)] [DestructuringDeclarationContainerVariableMarkerKey=true] lval <destruct>: R|kotlin/Pair<kotlin/Int, kotlin/Int>| = R|/pair|
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val first: <implicit> = R|<local>/<destruct>|.component1#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val first: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val last: <implicit> = R|<local>/<destruct>|.component2#()
|
public final [ResolvedTo(RAW_FIR)] [DestructuringDeclarationContainerVariableKey=<local>/<destruct>] val last: <implicit> = LAZY_EXPRESSION
|
||||||
|
|||||||
+36
-36
@@ -42,11 +42,11 @@ FILE: [ResolvedTo(RAW_FIR)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(RAW_FIR)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(RAW_FIR)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +97,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(RAW_FIR)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(RAW_FIR)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,11 +152,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,11 +207,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(COMPANION_GENERATION)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(COMPANION_GENERATION)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,11 +262,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(SUPER_TYPES)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(SUPER_TYPES)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,11 +317,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(TYPES)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(TYPES)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,11 +372,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(STATUS)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(STATUS)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,11 +427,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,11 +482,11 @@ FILE: [ResolvedTo(IMPORTS)] scriptStatementLevelAsLastStatement.kts
|
|||||||
public final [ResolvedTo(CONTRACTS)] val $$result: <implicit> = when () {
|
public final [ResolvedTo(CONTRACTS)] val $$result: <implicit> = when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval b: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval <destruct>: <implicit> = Pair#(LAZY_EXPRESSION, LAZY_EXPRESSION)
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@Anno[Unresolved](LAZY_EXPRESSION) [ResolvedTo(RAW_FIR)] lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -198,6 +198,14 @@ open class PsiRawFirBuilder(
|
|||||||
(this as KtAnnotated).extractAnnotationsTo(target)
|
(this as KtAnnotated).extractAnnotationsTo(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createComponentCall(
|
||||||
|
container: FirVariable,
|
||||||
|
entrySource: KtSourceElement?,
|
||||||
|
index: Int,
|
||||||
|
): FirExpression = buildOrLazyExpression(entrySource) {
|
||||||
|
super.createComponentCall(container, entrySource, index)
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun <reified R : FirElement> KtElement?.convertSafe(): R? =
|
private inline fun <reified R : FirElement> KtElement?.convertSafe(): R? =
|
||||||
this?.let { convertElement(it, null) } as? R
|
this?.let { convertElement(it, null) } as? R
|
||||||
|
|
||||||
@@ -1280,6 +1288,10 @@ open class PsiRawFirBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun configureScriptDestructuringDeclarationEntry(declaration: FirVariable, container: FirVariable) {
|
||||||
|
(declaration as FirProperty).destructuringDeclarationContainerVariable = container.symbol
|
||||||
|
}
|
||||||
|
|
||||||
protected fun buildScriptDestructuringDeclaration(destructuringDeclaration: KtDestructuringDeclaration): FirVariable {
|
protected fun buildScriptDestructuringDeclaration(destructuringDeclaration: KtDestructuringDeclaration): FirVariable {
|
||||||
val initializer = destructuringDeclaration.initializer
|
val initializer = destructuringDeclaration.initializer
|
||||||
val firInitializer = buildOrLazyExpression(initializer?.toFirSourceElement()) {
|
val firInitializer = buildOrLazyExpression(initializer?.toFirSourceElement()) {
|
||||||
@@ -1344,7 +1356,7 @@ open class PsiRawFirBuilder(
|
|||||||
tmpVariable = false,
|
tmpVariable = false,
|
||||||
localEntries = false,
|
localEntries = false,
|
||||||
) {
|
) {
|
||||||
(it as FirProperty).destructuringDeclarationContainerVariable = destructuringContainerVar.symbol
|
configureScriptDestructuringDeclarationEntry(it, destructuringContainerVar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
+4
-4
@@ -2,16 +2,16 @@ FILE: scriptLevelDestructuringWithAnnotation.kts
|
|||||||
SCRIPT: <script-scriptLevelDestructuringWithAnnotation.kts>
|
SCRIPT: <script-scriptLevelDestructuringWithAnnotation.kts>
|
||||||
|
|
||||||
@DestrAnno(LAZY_EXPRESSION) lval <destruct>: <implicit> = LAZY_EXPRESSION
|
@DestrAnno(LAZY_EXPRESSION) lval <destruct>: <implicit> = LAZY_EXPRESSION
|
||||||
@LeftAnno(LAZY_EXPRESSION) public final val a: <implicit> = R|<local>/<destruct>|.component1#()
|
@LeftAnno(LAZY_EXPRESSION) public final val a: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
@RightAnno(LAZY_EXPRESSION) public final val b: <implicit> = R|<local>/<destruct>|.component2#()
|
@RightAnno(LAZY_EXPRESSION) public final val b: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
@Destr2Anno(LAZY_EXPRESSION) lval <destruct>: <implicit> = LAZY_EXPRESSION
|
@Destr2Anno(LAZY_EXPRESSION) lval <destruct>: <implicit> = LAZY_EXPRESSION
|
||||||
@SecondLeftAnno(LAZY_EXPRESSION) public final val c: <implicit> = R|<local>/<destruct>|.component1#()
|
@SecondLeftAnno(LAZY_EXPRESSION) public final val c: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
@SecondRightAnno(LAZY_EXPRESSION) public final val d: <implicit> = R|<local>/<destruct>|.component2#()
|
@SecondRightAnno(LAZY_EXPRESSION) public final val d: <implicit> = LAZY_EXPRESSION
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -5,12 +5,12 @@ FILE: scriptStatementLevelDestructuringWithAnnotationAsLastStatement.kts
|
|||||||
when () {
|
when () {
|
||||||
Boolean(true) -> {
|
Boolean(true) -> {
|
||||||
@DestrAnno(LAZY_EXPRESSION) lval <destruct>: <implicit> = IntegerLiteral(0).to#(IntegerLiteral(1))
|
@DestrAnno(LAZY_EXPRESSION) lval <destruct>: <implicit> = IntegerLiteral(0).to#(IntegerLiteral(1))
|
||||||
@LeftAnno(LAZY_EXPRESSION) lval a: <implicit> = R|<local>/<destruct>|.component1#()
|
@LeftAnno(LAZY_EXPRESSION) lval a: <implicit> = LAZY_EXPRESSION
|
||||||
@RightAnno(LAZY_EXPRESSION) lval b: <implicit> = R|<local>/<destruct>|.component2#()
|
@RightAnno(LAZY_EXPRESSION) lval b: <implicit> = LAZY_EXPRESSION
|
||||||
run#(<L> = LAZY_EXPRESSION)
|
run#(<L> = LAZY_EXPRESSION)
|
||||||
@Destr2Anno(LAZY_EXPRESSION) lval <destruct>: <implicit> = IntegerLiteral(2).to#(IntegerLiteral(3))
|
@Destr2Anno(LAZY_EXPRESSION) lval <destruct>: <implicit> = IntegerLiteral(2).to#(IntegerLiteral(3))
|
||||||
@SecondLeftAnno(LAZY_EXPRESSION) lval c: <implicit> = R|<local>/<destruct>|.component1#()
|
@SecondLeftAnno(LAZY_EXPRESSION) lval c: <implicit> = LAZY_EXPRESSION
|
||||||
@SecondRightAnno(LAZY_EXPRESSION) lval d: <implicit> = R|<local>/<destruct>|.component2#()
|
@SecondRightAnno(LAZY_EXPRESSION) lval d: <implicit> = LAZY_EXPRESSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-15
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirVariable
|
import org.jetbrains.kotlin.fir.declarations.FirVariable
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
|
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
@@ -23,6 +24,9 @@ interface DestructuringContext<T> {
|
|||||||
val T.name: Name
|
val T.name: Name
|
||||||
val T.source: KtSourceElement
|
val T.source: KtSourceElement
|
||||||
fun T.extractAnnotationsTo(target: FirAnnotationContainerBuilder, containerSymbol: FirBasedSymbol<*>)
|
fun T.extractAnnotationsTo(target: FirAnnotationContainerBuilder, containerSymbol: FirBasedSymbol<*>)
|
||||||
|
fun createComponentCall(container: FirVariable, entrySource: KtSourceElement?, index: Int): FirExpression {
|
||||||
|
return container.toComponentCall(entrySource, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context(AbstractRawFirBuilder<*>, DestructuringContext<T>)
|
context(AbstractRawFirBuilder<*>, DestructuringContext<T>)
|
||||||
@@ -39,20 +43,39 @@ fun <T> MutableList<in FirVariable>.addDestructuringVariables(
|
|||||||
this += container
|
this += container
|
||||||
}
|
}
|
||||||
for ((index, entry) in entries.withIndex()) {
|
for ((index, entry) in entries.withIndex()) {
|
||||||
this += buildProperty {
|
this += buildDestructuringVariable(
|
||||||
symbol = FirPropertySymbol(entry.name)
|
moduleData,
|
||||||
withContainerSymbol(symbol, localEntries) {
|
container,
|
||||||
this.moduleData = moduleData
|
entry,
|
||||||
origin = FirDeclarationOrigin.Source
|
isVar,
|
||||||
returnTypeRef = entry.returnTypeRef
|
localEntries,
|
||||||
name = entry.name
|
index,
|
||||||
initializer = container.toComponentCall(entry.source, index)
|
configure,
|
||||||
this.isVar = isVar
|
)
|
||||||
source = entry.source
|
|
||||||
isLocal = localEntries
|
|
||||||
status = FirDeclarationStatusImpl(if (localEntries) Visibilities.Local else Visibilities.Public, Modality.FINAL)
|
|
||||||
entry.extractAnnotationsTo(this, context.containerSymbol)
|
|
||||||
}
|
|
||||||
}.also(configure)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context(AbstractRawFirBuilder<*>, DestructuringContext<T>)
|
||||||
|
fun <T> buildDestructuringVariable(
|
||||||
|
moduleData: FirModuleData,
|
||||||
|
container: FirVariable,
|
||||||
|
entry: T,
|
||||||
|
isVar: Boolean,
|
||||||
|
localEntries: Boolean,
|
||||||
|
index: Int,
|
||||||
|
configure: (FirVariable) -> Unit = {}
|
||||||
|
): FirVariable = buildProperty {
|
||||||
|
symbol = FirPropertySymbol(entry.name)
|
||||||
|
withContainerSymbol(symbol, localEntries) {
|
||||||
|
this.moduleData = moduleData
|
||||||
|
origin = FirDeclarationOrigin.Source
|
||||||
|
returnTypeRef = entry.returnTypeRef
|
||||||
|
name = entry.name
|
||||||
|
initializer = createComponentCall(container, entry.source, index)
|
||||||
|
this.isVar = isVar
|
||||||
|
source = entry.source
|
||||||
|
isLocal = localEntries
|
||||||
|
status = FirDeclarationStatusImpl(if (localEntries) Visibilities.Local else Visibilities.Public, Modality.FINAL)
|
||||||
|
entry.extractAnnotationsTo(this, context.containerSymbol)
|
||||||
|
}
|
||||||
|
}.also(configure)
|
||||||
Reference in New Issue
Block a user