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

82 lines
1.9 KiB
Kotlin
Vendored

enum class B(val x: Int) {
B1(1),
B2(2);
companion object {
val SUM = B1.x + B2.x
val COPY = B1
}
}
enum class C(val x: Int) {
C1(<!UNINITIALIZED_ENUM_COMPANION, UNINITIALIZED_VARIABLE!>SUM<!>),
C2(1);
companion object {
val COPY = C2
val SUM = C1.x + COPY.x
}
}
// From KT-11769
enum class Fruit(personal: Int) {
APPLE(1);
companion object {
val common = 20
}
val score = personal + <!UNINITIALIZED_VARIABLE!>common<!>
val score2 = { personal + common }()
}
// Another example from KT-11769
enum class EnumCompanion1(val x: Int) {
INSTANCE(<!UNINITIALIZED_ENUM_COMPANION!>Companion<!>.foo()),
ANOTHER(<!UNINITIALIZED_ENUM_COMPANION!>foo()<!>);
companion object {
fun foo() = 42
}
}
// Also should be reported for implicit receiver
enum class EnumCompanion2(val x: Int) {
INSTANCE(<!UNINITIALIZED_ENUM_COMPANION!>foo()<!>);
companion object {
fun foo() = 42
}
}
// But not for another enum
enum class EnumCompanion3(val x: Int) {
INSTANCE(EnumCompanion1.foo()),
ANOTHER(EnumCompanion2.foo());
companion object
}
interface ExtractableCodeDescriptor {
fun isInterface(): Boolean
}
enum class ExtractionTarget(val targetName: String) {
FUNCTION("function") {
override fun isAvailable(descriptor: ExtractableCodeDescriptor) = true
},
LAZY_PROPERTY("lazy property") {
override fun isAvailable(descriptor: ExtractableCodeDescriptor): Boolean {
// Should not report UNINITIALIZED_ENUM_COMPANION
return checkNotTrait(descriptor)
}
};
abstract fun isAvailable(descriptor: ExtractableCodeDescriptor): Boolean
companion object {
fun checkNotTrait(descriptor: ExtractableCodeDescriptor): Boolean {
return !descriptor.isInterface()
}
}
}