[FIR] Create separated FirBlock for loop local val

Refactor FIR builders code for ForExpression
This commit is contained in:
Ivan Kochurkin
2022-12-05 18:02:22 +01:00
committed by Space Team
parent e49bb1fe37
commit a3e7a35cb1
30 changed files with 1426 additions and 1222 deletions
@@ -1,3 +1,4 @@
// FIR_DUMP
// ISSUE: KT-54405
class A {
@@ -5,7 +6,7 @@ class A {
operator fun component2() = ""
}
fun test(b: Boolean) {
fun testRedeclaration(b: Boolean) {
val <!REDECLARATION!>y<!> = 1
val <!REDECLARATION!>y<!> = 2
val <!REDECLARATION!>`_`<!> = 3
@@ -14,15 +15,16 @@ fun test(b: Boolean) {
var <!REDECLARATION!>a<!> = 10
var <!REDECLARATION!>a<!> = 11
}
}
fun testNoRedeclaration(list: List<Int>, b: Boolean) {
for (el in list) {
val el = 42
}
if (b) {
val z = 3
val <!REDECLARATION!>x<!> = 5
val <!REDECLARATION!>x<!> = 6
} else {
val z = 4
}
}
fun test2() {
val (`_`, _) = A()
}
@@ -0,0 +1,51 @@
FILE: RedeclaredValsAndVars.fir.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final operator fun component1(): R|kotlin/Int| {
^component1 Int(1)
}
public final operator fun component2(): R|kotlin/String| {
^component2 String()
}
}
public final fun testRedeclaration(b: R|kotlin/Boolean|): R|kotlin/Unit| {
lval y: R|kotlin/Int| = Int(1)
lval y: R|kotlin/Int| = Int(2)
lval _: R|kotlin/Int| = Int(3)
lval _: R|kotlin/Int| = Int(4)
fun <anonymous>(): R|kotlin/Unit| <inline=Unknown> {
lvar a: R|kotlin/Int| = Int(10)
lvar a: R|kotlin/Int| = Int(11)
}
}
public final fun testNoRedeclaration(list: R|kotlin/collections/List<kotlin/Int>|, b: R|kotlin/Boolean|): R|kotlin/Unit| {
{
lval <iterator>: R|kotlin/collections/Iterator<kotlin/Int>| = R|<local>/list|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<kotlin/Int>|>|()
while(R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()) {
lval el: R|kotlin/Int| = R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|kotlin/Int|>|()
{
lval el: R|kotlin/Int| = Int(42)
}
}
}
when () {
R|<local>/b| -> {
lval z: R|kotlin/Int| = Int(3)
}
else -> {
lval z: R|kotlin/Int| = Int(4)
}
}
lval <destruct>: R|A| = R|/A.A|()
lval _: R|kotlin/Int| = R|<local>/<destruct>|.R|/A.component1|()
}
@@ -1,3 +1,4 @@
// FIR_DUMP
// ISSUE: KT-54405
class A {
@@ -5,7 +6,7 @@ class A {
operator fun component2() = ""
}
fun test(b: Boolean) {
fun testRedeclaration(b: Boolean) {
val <!REDECLARATION!>y<!> = 1
val <!NAME_SHADOWING, REDECLARATION!>y<!> = 2
val <!REDECLARATION!>`_`<!> = 3
@@ -14,15 +15,16 @@ fun test(b: Boolean) {
var <!REDECLARATION!>a<!> = 10
var <!NAME_SHADOWING, REDECLARATION!>a<!> = 11
}
}
fun testNoRedeclaration(list: List<Int>, b: Boolean) {
for (el in list) {
val <!NAME_SHADOWING!>el<!> = 42
}
if (b) {
val z = 3
val <!REDECLARATION!>x<!> = 5
val <!NAME_SHADOWING, REDECLARATION!>x<!> = 6
} else {
val z = 4
}
}
fun test2() {
val (`_`, _) = A()
}
@@ -1,7 +1,7 @@
package
public fun test(/*0*/ b: kotlin.Boolean): kotlin.Unit
public fun test2(): kotlin.Unit
public fun testNoRedeclaration(/*0*/ list: kotlin.collections.List<kotlin.Int>, /*1*/ b: kotlin.Boolean): kotlin.Unit
public fun testRedeclaration(/*0*/ b: kotlin.Boolean): kotlin.Unit
public final class A {
public constructor A()