Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/accessToCompanionInBaseEnumInitSection_property.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

145 lines
4.5 KiB
Kotlin
Vendored

// DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_STDLIB
// ISSUE: KT-57456, KT-57608
@file:OptIn(ExperimentalContracts::class)
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
enum class Enum {
A {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
},
B {
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
},
C {
init {
class Local {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
},
D {
init {
val someObj = object {
val aInside = <!UNINITIALIZED_VARIABLE!>value<!>
val bInside = inPlaceRun { value }
val cInside = nonInPlaceRun { value }
val dInside by <!UNINITIALIZED_VARIABLE!>value<!>
val eInside by inPlaceDelegate { value }
val fInside by nonInPlaceDelegate { value }
init {
val aInit = <!UNINITIALIZED_VARIABLE!>value<!>
val bInit = inPlaceRun { value }
val cInit = nonInPlaceRun { value }
val dInit by <!UNINITIALIZED_VARIABLE!>value<!>
val eInit by inPlaceDelegate { value }
val fInit by nonInPlaceDelegate { value }
}
fun localFun() {
val a = value
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by value
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
}
}
}
}
;
val a = <!UNINITIALIZED_VARIABLE!>value<!>
val b = inPlaceRun { value }
val c = nonInPlaceRun { value }
val d by <!UNINITIALIZED_VARIABLE!>value<!>
val e by inPlaceDelegate { value }
val f by nonInPlaceDelegate { value }
companion object {
val value = "value"
}
}
enum class EnumWithConstructor(val a: String, val b: String, val c: String) {
A(
a = <!UNINITIALIZED_ENUM_COMPANION, UNINITIALIZED_VARIABLE!>value<!>,
b = inPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>value<!> },
c = nonInPlaceRun { <!UNINITIALIZED_ENUM_COMPANION!>value<!> }
);
companion object {
val value = "value"
}
}
operator fun <T> T.provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty<Any?, T> = ReadOnlyProperty { _, _ -> this }
inline fun <T> inPlaceRun(block: () -> T): T {
contract { callsInPlace(block) }
return block()
}
fun <T> nonInPlaceRun(block: () -> T): T {
return block()
}
inline fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
contract { callsInPlace(block) }
val value = block()
return ReadOnlyProperty { _, _ -> value }
}
fun <T> nonInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, _ -> block() }
}