[FIR] Run CFA for member properties even if they have initializer

^KT-56678 Fixed
^KT-56682 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-02-15 12:31:26 +02:00
committed by Space Team
parent de84cb8038
commit c87e489dc9
28 changed files with 306 additions and 59 deletions
@@ -255,8 +255,8 @@ class Outer() {
}
class ForwardAccessToBackingField() { //kt-147
val a = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>a<!> // error
val b = c // error
val a = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>a<!> // error
val b = <!UNINITIALIZED_VARIABLE!>c<!> // error
val c = 1
}
@@ -0,0 +1,40 @@
// DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
interface Delegate<V> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): V = null!!
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {}
}
fun <V> delegate(): Delegate<V> = null!!
fun consume(x: Any?) {}
class A {
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>)
<!INITIALIZATION_BEFORE_DECLARATION!>x<!> = 10
}
val x: Int by delegate()
init {
<!VAL_REASSIGNMENT!>x<!> = 10
consume(x)
}
}
class B {
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>)
<!INITIALIZATION_BEFORE_DECLARATION!>x<!> = 10
}
var x: Int by delegate()
init {
x = 10
consume(x)
}
}
@@ -0,0 +1,40 @@
// DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
interface Delegate<V> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): V = null!!
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {}
}
fun <V> delegate(): Delegate<V> = null!!
fun consume(x: Any?) {}
class A {
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>)
<!VAL_REASSIGNMENT!>x<!> = 10
}
val x: Int by delegate()
init {
x = 10
consume(x)
}
}
class B {
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>)
<!INITIALIZATION_BEFORE_DECLARATION!>x<!> = 10
}
var x: Int by delegate()
init {
x = 10
consume(x)
}
}
@@ -1,4 +1,4 @@
// See also KT-10869: Accessing lazy properties from init causes IllegalArgumentException
// ISSUE: KT-10869, KT-56682
import kotlin.reflect.KProperty
@@ -9,14 +9,14 @@ class CustomDelegate {
class Kaboom() {
// Here and below we should have errors for simple AND delegated
init {
delegated.hashCode()
simple.hashCode()
<!UNINITIALIZED_VARIABLE!>delegated<!>.hashCode()
<!UNINITIALIZED_VARIABLE!>simple<!>.hashCode()
withGetter.hashCode()
}
val other = delegated
val other = <!UNINITIALIZED_VARIABLE!>delegated<!>
val another = simple
val another = <!UNINITIALIZED_VARIABLE!>simple<!>
val something = withGetter
@@ -1,4 +1,4 @@
// See also KT-10869: Accessing lazy properties from init causes IllegalArgumentException
// ISSUE: KT-10869, KT-56682
import kotlin.reflect.KProperty
@@ -1,20 +0,0 @@
//KT-897 Don't allow assignment to a property before it is defined
package kt897
class A() {
init {
<!INITIALIZATION_BEFORE_DECLARATION, VAL_REASSIGNMENT!>i<!> = 11
}
val i : Int? = null // must be an error
init {
<!INITIALIZATION_BEFORE_DECLARATION!>j<!> = 1
}
var j : Int = 2
init {
<!INITIALIZATION_BEFORE_DECLARATION!>k<!> = 3
}
val k : Int
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-897 Don't allow assignment to a property before it is defined
package kt897
@@ -0,0 +1,87 @@
fun println(obj: Any?) = obj
class Demo0 {
private val some = object {
fun foo() {
println(state)
}
}
private var state: Boolean = true
}
class Demo1 {
private val some = object {
fun foo() {
if (state)
state = true
println(state)
}
}
private var state: Boolean = true
}
class Demo1A {
fun foo() {
if (state)
state = true
println(state)
}
private var state: Boolean = true
}
class Demo2 {
private val some = object {
fun foo() {
if (state)
state = true
else
state = false
println(state)
}
}
private var state: Boolean = true
}
class Demo3 {
private val some = run {
if (state)
state = true
println(state)
}
private var state: Boolean = true
}
fun <T> exec(f: () -> T): T = f()
class Demo4 {
private val some = exec {
if (<!UNINITIALIZED_VARIABLE!>state<!>)
state = true
println(<!UNINITIALIZED_VARIABLE!>state<!>)
}
private var state: Boolean = true
}
class Demo5 {
private var state: Boolean = true
private val some = object {
fun foo() {
if (state)
state = true
println(state)
}
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
fun println(obj: Any?) = obj
class Demo0 {
@@ -11,22 +11,22 @@ class TestFunctionLiteral {
open class A(val a: A)
class TestObjectLiteral {
val obj: A = object: A(obj) {
val obj: A = object: A(<!UNINITIALIZED_VARIABLE!>obj<!>) {
init {
val x = obj
val x = <!UNINITIALIZED_VARIABLE!>obj<!>
}
fun foo() {
val y = obj
}
}
val obj1: A = l@ ( object: A(obj1) {
val obj1: A = l@ ( object: A(<!UNINITIALIZED_VARIABLE!>obj1<!>) {
init {
val x = obj1
val x = <!UNINITIALIZED_VARIABLE!>obj1<!>
}
fun foo() = obj1
})
}
class TestOther {
val x: Int = x + 1
val x: Int = <!UNINITIALIZED_VARIABLE!>x<!> + 1
}
@@ -4,8 +4,8 @@ val a : Int = b
val b : Int = a + b
class C {
val a : Int = b
val b : Int = a + b
val a : Int = <!UNINITIALIZED_VARIABLE!>b<!>
val b : Int = a + <!UNINITIALIZED_VARIABLE!>b<!>
}
fun foo() {
@@ -0,0 +1,18 @@
// FIR_IDENTICAL
// ISSUE: KT-56678
class A {
val b = <!UNINITIALIZED_VARIABLE!>a<!>
val a = 1
val c = a
}
class B {
val b = <!UNINITIALIZED_VARIABLE!>a<!>
val a: Int
val c = <!UNINITIALIZED_VARIABLE!>a<!>
init {
a = 1
}
val d = a
}