Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLocalClass.fir.kt
T
Dmitrii Gridin 72def186a3 [LL FIR] rework transformers, so transformers resolve only a specific set of declarations
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
2023-04-19 20:12:38 +00:00

91 lines
1.5 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
fun foo() {
var x: String
class A {
init {
x = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
}
fun bar() {
var x: String
object: Any() {
init {
x = ""
}
}
// Ok
x.length
}
fun gav() {
val x: String
class B {
init {
// Error! See KT-10445
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
}
}
// Error! See KT-10042
<!UNINITIALIZED_VARIABLE!>x<!>.length
val y: String
class C(val s: String) {
constructor(): this("") {
// Error!
<!CAPTURED_VAL_INITIALIZATION!>y<!> = s
}
}
<!UNINITIALIZED_VARIABLE!>y<!>.length
}
open class Gau(val s: String)
fun gau() {
val x: String
object: Any() {
init {
// Ok
x = ""
}
}
// Ok
x.length
val y: String
fun local() {
object: Any() {
init {
// Error!
<!CAPTURED_VAL_INITIALIZATION!>y<!> = ""
}
}
}
val z: String
object: Gau(if (true) {
z = ""
z
}
else "") {}
}
class My {
init {
val x: String
class Your {
init {
// Error! See KT-10445
<!CAPTURED_VAL_INITIALIZATION!>x<!> = ""
}
}
}
}
<!MUST_BE_INITIALIZED!>val top: Int<!>
fun init() {
<!VAL_REASSIGNMENT!>top<!> = 1
}