[LL FIR] fix getOrBuildFir for destructing declaration inside lambda parameter

This commit is contained in:
Ilya Kirillov
2023-08-15 18:47:45 +02:00
committed by Space Team
parent 73b2ccff76
commit 04b9faf9e6
14 changed files with 314 additions and 0 deletions
@@ -114,6 +114,8 @@ internal class KtToFirMapping(firElement: FirElement) {
}
// Enum entries/annotation entries constructor calls
is KtConstructorCalleeExpression -> getElement(current.parent as KtCallElement)
// KtParameter for destructuring declaration
is KtParameter -> getElement(current as KtElement)
else -> null
}
}
@@ -0,0 +1,7 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtDestructuringDeclaration
data class X(val a: Int, val b: Int)
fun main(x: X) {
<expr>val (a, b) = x</expr>
}
@@ -0,0 +1,32 @@
KT element: KtDestructuringDeclaration
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
[ResolvedTo(BODY_RESOLVE)] lval <destruct>: R|X| = R|<local>/x|
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] destructuringDeclaration.kt
public final data [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=X] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/X.a] a: R|kotlin/Int|, [ResolvedTo(STATUS)] [CorrespondingProperty=/X.b] b: R|kotlin/Int|): R|X| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component1, IsFromPrimaryConstructor=true] val a: R|kotlin/Int| = R|<local>/a|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component2, IsFromPrimaryConstructor=true] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component1(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component2(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] fun copy([ResolvedTo(STATUS)] a: R|kotlin/Int| = this@R|/X|.R|/X.a|, [ResolvedTo(STATUS)] b: R|kotlin/Int| = this@R|/X|.R|/X.b|): R|X|
}
public final [ResolvedTo(BODY_RESOLVE)] fun main([ResolvedTo(BODY_RESOLVE)] x: R|X|): R|kotlin/Unit| {
[ResolvedTo(BODY_RESOLVE)] lval <destruct>: R|X| = R|<local>/x|
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
[ResolvedTo(BODY_RESOLVE)] lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component2|()
}
@@ -0,0 +1,11 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtDestructuringDeclaration
data class X(val a: Int, val b: Int)
fun x(action: (X) -> Unit) {}
fun main() {
x { <expr>(a, b)</expr> ->
}
}
@@ -0,0 +1,37 @@
KT element: KtDestructuringDeclaration
FIR element: FirValueParameterImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
[ResolvedTo(BODY_RESOLVE)] <destruct>: R|X|
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] destructuringDeclarationInLambda.kt
public final data [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=X] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/X.a] a: R|kotlin/Int|, [ResolvedTo(STATUS)] [CorrespondingProperty=/X.b] b: R|kotlin/Int|): R|X| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component1, IsFromPrimaryConstructor=true] val a: R|kotlin/Int| = R|<local>/a|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component2, IsFromPrimaryConstructor=true] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component1(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component2(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] fun copy([ResolvedTo(STATUS)] a: R|kotlin/Int| = this@R|/X|.R|/X.a|, [ResolvedTo(STATUS)] b: R|kotlin/Int| = this@R|/X|.R|/X.b|): R|X|
}
public final [ResolvedTo(CONTRACTS)] fun x([ResolvedTo(CONTRACTS)] action: R|(X) -> kotlin/Unit|): R|kotlin/Unit| {
}
public final [ResolvedTo(BODY_RESOLVE)] fun main(): R|kotlin/Unit| {
R|/x|(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<X, kotlin/Unit>] x@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] <destruct>: R|X|): R|kotlin/Unit| <inline=NoInline> {
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
[ResolvedTo(BODY_RESOLVE)] lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component2|()
^@x Unit
}
)
}
@@ -0,0 +1,11 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtParameter
data class X(val a: Int, val b: Int)
fun x(action: (X, Int) -> Unit) {}
fun main() {
x { <expr>(a, b)</expr>, i ->
}
}
@@ -0,0 +1,37 @@
KT element: KtParameter
FIR element: FirValueParameterImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
[ResolvedTo(BODY_RESOLVE)] <destruct>: R|X|
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] destructuringDeclarationParameterInLambda.kt
public final data [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=X] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/X.a] a: R|kotlin/Int|, [ResolvedTo(STATUS)] [CorrespondingProperty=/X.b] b: R|kotlin/Int|): R|X| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component1, IsFromPrimaryConstructor=true] val a: R|kotlin/Int| = R|<local>/a|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component2, IsFromPrimaryConstructor=true] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component1(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component2(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] fun copy([ResolvedTo(STATUS)] a: R|kotlin/Int| = this@R|/X|.R|/X.a|, [ResolvedTo(STATUS)] b: R|kotlin/Int| = this@R|/X|.R|/X.b|): R|X|
}
public final [ResolvedTo(CONTRACTS)] fun x([ResolvedTo(CONTRACTS)] action: R|(X, kotlin/Int) -> kotlin/Unit|): R|kotlin/Unit| {
}
public final [ResolvedTo(BODY_RESOLVE)] fun main(): R|kotlin/Unit| {
R|/x|(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function2<X, kotlin/Int, kotlin/Unit>] x@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] <destruct>: R|X|, [ResolvedTo(BODY_RESOLVE)] i: R|kotlin/Int|): R|kotlin/Unit| <inline=NoInline> {
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
[ResolvedTo(BODY_RESOLVE)] lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component2|()
^@x Unit
}
)
}
@@ -0,0 +1,7 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry
data class X(val a: Int, val b: Int)
fun main(x: X) {
val (<expr>a</expr>, b) = x
}
@@ -0,0 +1,32 @@
KT element: KtDestructuringDeclarationEntry
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] entryInDestructuringDeclaration.kt
public final data [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=X] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/X.a] a: R|kotlin/Int|, [ResolvedTo(STATUS)] [CorrespondingProperty=/X.b] b: R|kotlin/Int|): R|X| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component1, IsFromPrimaryConstructor=true] val a: R|kotlin/Int| = R|<local>/a|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component2, IsFromPrimaryConstructor=true] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component1(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component2(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] fun copy([ResolvedTo(STATUS)] a: R|kotlin/Int| = this@R|/X|.R|/X.a|, [ResolvedTo(STATUS)] b: R|kotlin/Int| = this@R|/X|.R|/X.b|): R|X|
}
public final [ResolvedTo(BODY_RESOLVE)] fun main([ResolvedTo(BODY_RESOLVE)] x: R|X|): R|kotlin/Unit| {
[ResolvedTo(BODY_RESOLVE)] lval <destruct>: R|X| = R|<local>/x|
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
[ResolvedTo(BODY_RESOLVE)] lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component2|()
}
@@ -0,0 +1,11 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry
data class X(val a: Int, val b: Int)
fun x(action: (X) -> Unit) {}
fun main() {
x { (<expr>a</expr>, b) ->
}
}
@@ -0,0 +1,37 @@
KT element: KtDestructuringDeclarationEntry
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] entryInDestructuringDeclarationParameterInLambda.kt
public final data [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=X] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/X.a] a: R|kotlin/Int|, [ResolvedTo(STATUS)] [CorrespondingProperty=/X.b] b: R|kotlin/Int|): R|X| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component1, IsFromPrimaryConstructor=true] val a: R|kotlin/Int| = R|<local>/a|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] [ComponentFunctionSymbolKey=/X.component2, IsFromPrimaryConstructor=true] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] [ContainingClassKey=X] get(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component1(): R|kotlin/Int|
public final operator [ResolvedTo(CONTRACTS)] fun component2(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] fun copy([ResolvedTo(STATUS)] a: R|kotlin/Int| = this@R|/X|.R|/X.a|, [ResolvedTo(STATUS)] b: R|kotlin/Int| = this@R|/X|.R|/X.b|): R|X|
}
public final [ResolvedTo(CONTRACTS)] fun x([ResolvedTo(CONTRACTS)] action: R|(X) -> kotlin/Unit|): R|kotlin/Unit| {
}
public final [ResolvedTo(BODY_RESOLVE)] fun main(): R|kotlin/Unit| {
R|/x|(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<X, kotlin/Unit>] x@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] <destruct>: R|X|): R|kotlin/Unit| <inline=NoInline> {
[ResolvedTo(BODY_RESOLVE)] lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component1|()
[ResolvedTo(BODY_RESOLVE)] lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|/X.component2|()
^@x Unit
}
)
}
@@ -568,6 +568,46 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@TestMetadata("destructuringDeclaration.kt")
public void testDestructuringDeclaration() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclaration.kt");
}
@Test
@TestMetadata("destructuringDeclarationInLambda.kt")
public void testDestructuringDeclarationInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclarationInLambda.kt");
}
@Test
@TestMetadata("destructuringDeclarationParameterInLambda.kt")
public void testDestructuringDeclarationParameterInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclarationParameterInLambda.kt");
}
@Test
@TestMetadata("entryInDestructuringDeclaration.kt")
public void testEntryInDestructuringDeclaration() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/entryInDestructuringDeclaration.kt");
}
@Test
@TestMetadata("entryInDestructuringDeclarationParameterInLambda.kt")
public void testEntryInDestructuringDeclarationParameterInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/entryInDestructuringDeclarationParameterInLambda.kt");
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/expressions")
@TestDataPath("$PROJECT_ROOT")
@@ -412,6 +412,16 @@ public class ScriptGetOrBuildFirTestGenerated extends AbstractScriptGetOrBuildFi
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/expressions")
@TestDataPath("$PROJECT_ROOT")
@@ -568,6 +568,46 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring")
@TestDataPath("$PROJECT_ROOT")
public class Destructuring {
@Test
public void testAllFilesPresentInDestructuring() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@TestMetadata("destructuringDeclaration.kt")
public void testDestructuringDeclaration() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclaration.kt");
}
@Test
@TestMetadata("destructuringDeclarationInLambda.kt")
public void testDestructuringDeclarationInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclarationInLambda.kt");
}
@Test
@TestMetadata("destructuringDeclarationParameterInLambda.kt")
public void testDestructuringDeclarationParameterInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/destructuringDeclarationParameterInLambda.kt");
}
@Test
@TestMetadata("entryInDestructuringDeclaration.kt")
public void testEntryInDestructuringDeclaration() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/entryInDestructuringDeclaration.kt");
}
@Test
@TestMetadata("entryInDestructuringDeclarationParameterInLambda.kt")
public void testEntryInDestructuringDeclarationParameterInLambda() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/destructuring/entryInDestructuringDeclarationParameterInLambda.kt");
}
}
@Nested
@TestMetadata("analysis/low-level-api-fir/testdata/getOrBuildFir/expressions")
@TestDataPath("$PROJECT_ROOT")