[FIR] Consistent isLocal for objects inside Enum entries
This commit is contained in:
committed by
TeamCityServer
parent
7084fec651
commit
27766c2575
+4
-2
@@ -90,10 +90,12 @@ inline fun isClassLocal(classNode: LighterASTNode, getParent: LighterASTNode.()
|
||||
parent?.tokenType == KT_FILE -> return true
|
||||
parent?.tokenType == CLASS_BODY && !(grandParent?.tokenType == OBJECT_DECLARATION && grandParent?.getParent()?.tokenType == OBJECT_LITERAL) -> return true
|
||||
parent?.tokenType == BLOCK && grandParent?.tokenType == SCRIPT -> return true
|
||||
// NB: enum entry nested classes are considered local by FIR design (see discussion in KT-45115)
|
||||
parent?.tokenType == ENUM_ENTRY -> return true
|
||||
}
|
||||
}
|
||||
// NB: enum entry nested classes are considered local by FIR design (see discussion in KT-45115)
|
||||
if (parent?.tokenType == ENUM_ENTRY) {
|
||||
return true
|
||||
}
|
||||
if (tokenType == BLOCK) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -793,10 +793,11 @@ open class RawFirBuilder(
|
||||
}
|
||||
|
||||
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement {
|
||||
// NB: enum entry nested classes are considered local by FIR design (see discussion in KT-45115)
|
||||
val isLocal = classOrObject.isLocal || classOrObject.getStrictParentOfType<KtEnumEntry>() != null
|
||||
return withChildClassName(
|
||||
classOrObject.nameAsSafeName,
|
||||
// NB: enum entry nested classes are considered local by FIR design (see discussion in KT-45115)
|
||||
isLocal = classOrObject.isLocal || classOrObject.getStrictParentOfType<KtEnumEntry>() != null
|
||||
isLocal = isLocal
|
||||
) {
|
||||
val classKind = when (classOrObject) {
|
||||
is KtObjectDeclaration -> ClassKind.OBJECT
|
||||
@@ -809,7 +810,7 @@ open class RawFirBuilder(
|
||||
else -> throw AssertionError("Unexpected class or object: ${classOrObject.text}")
|
||||
}
|
||||
val status = FirDeclarationStatusImpl(
|
||||
if (classOrObject.isLocal) Visibilities.Local else classOrObject.visibility,
|
||||
if (isLocal) Visibilities.Local else classOrObject.visibility,
|
||||
classOrObject.modality,
|
||||
).apply {
|
||||
isExpect = classOrObject.hasExpectModifier()
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
enum class E {
|
||||
ENTRY,
|
||||
SUBCLASS {
|
||||
// Because of KT-45115 classes/objects inside enum entries are local in FIR
|
||||
@Suppress("LOCAL_OBJECT_NOT_ALLOWED")
|
||||
object O {
|
||||
fun foo() = 2
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ package a
|
||||
|
||||
enum class C {
|
||||
E1, E2, E3 {
|
||||
object O_O
|
||||
<!LOCAL_OBJECT_NOT_ALLOWED!>object O_O<!>
|
||||
|
||||
fun b() {
|
||||
O_O
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ package a
|
||||
|
||||
enum class C {
|
||||
E1, E2, E3 {
|
||||
object O_O
|
||||
<!LOCAL_OBJECT_NOT_ALLOWED!>object O_O<!>
|
||||
|
||||
fun b() {
|
||||
O_O
|
||||
|
||||
@@ -18,13 +18,13 @@ FILE fqName:<root> fileName:/enumEntry.kt
|
||||
FUN name:test visibility:public modality:FINAL <> ($this:<root>.Z.ENTRY) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Z.ENTRY
|
||||
BLOCK_BODY
|
||||
CLASS CLASS name:A modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
|
||||
CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Z.ENTRY.A
|
||||
CONSTRUCTOR visibility:public <> ($this:<root>.Z.ENTRY) returnType:<root>.Z.ENTRY.A [primary]
|
||||
$outer: VALUE_PARAMETER name:<this> type:<root>.Z.ENTRY
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:local [inner] superTypes:[kotlin.Any]'
|
||||
FUN name:test2 visibility:public modality:FINAL <> ($this:<root>.Z.ENTRY.A) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Z.ENTRY.A
|
||||
BLOCK_BODY
|
||||
|
||||
Reference in New Issue
Block a user