From 356788030377ce42f06d1f5109435cada5ed1d72 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 4 Jun 2020 11:29:20 +0300 Subject: [PATCH] [FIR] Consider enum entry nested classes as local --- .../kotlin/fir/lightTree/converter/ConverterUtil.kt | 1 + .../src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt | 6 ++++-- .../kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt | 2 +- .../outerEnumEntryCapturedInLambdaInInnerClass.kt | 1 - .../enum/enumEntryReferenceFromInnerClassConstructor1.kt | 1 - .../enum/enumEntryReferenceFromInnerClassConstructor2.kt | 1 - compiler/testData/ir/irText/singletons/enumEntry.fir.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt index f4da426a597..07e2458c9ef 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ConverterUtil.kt @@ -89,6 +89,7 @@ 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 + parent?.tokenType == ENUM_ENTRY -> return true } } if (tokenType == BLOCK) { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 3892c8b0c0f..f8114bb3002 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -648,8 +648,10 @@ class RawFirBuilder( } override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement { - return withChildClassName(classOrObject.nameAsSafeName, classOrObject.isLocal) { - + return withChildClassName( + classOrObject.nameAsSafeName, + classOrObject.isLocal || classOrObject.getStrictParentOfType() != null + ) { val classKind = when (classOrObject) { is KtObjectDeclaration -> ClassKind.OBJECT is KtClass -> when { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index 7e38c693d81..c471ec72499 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -288,7 +288,7 @@ class ControlFlowGraphBuilder { fun exitLocalClass(klass: FirRegularClass): Pair { val graph = exitClass(klass) val node = createLocalClassExitNode(klass).also { - addNewSimpleNode(it) + addNewSimpleNodeIfPossible(it) } return node to graph } diff --git a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerEnumEntryCapturedInLambdaInInnerClass.kt b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerEnumEntryCapturedInLambdaInInnerClass.kt index e30b74b9ce3..1efe120d20a 100644 --- a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerEnumEntryCapturedInLambdaInInnerClass.kt +++ b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerEnumEntryCapturedInLambdaInInnerClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class Base(val fn: () -> Test) enum class Test(val ok: String) { diff --git a/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor1.kt b/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor1.kt index 3e2a0ee4cfb..135eeffae89 100644 --- a/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor1.kt +++ b/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor1.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface IFoo { fun foo(): String } diff --git a/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor2.kt b/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor2.kt index 12f9957cc98..7745c582462 100644 --- a/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor2.kt +++ b/compiler/testData/codegen/box/enum/enumEntryReferenceFromInnerClassConstructor2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface IFoo { fun foo(): String } diff --git a/compiler/testData/ir/irText/singletons/enumEntry.fir.txt b/compiler/testData/ir/irText/singletons/enumEntry.fir.txt index 6abb64f3f73..023d1a3d87b 100644 --- a/compiler/testData/ir/irText/singletons/enumEntry.fir.txt +++ b/compiler/testData/ir/irText/singletons/enumEntry.fir.txt @@ -20,7 +20,7 @@ FILE fqName: fileName:/enumEntry.kt BLOCK_BODY CLASS CLASS name:A modality:FINAL visibility:public [inner] superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z.ENTRY.A - CONSTRUCTOR visibility:public <> ($this:.Z.ENTRY) returnType:IrErrorType [primary] + CONSTRUCTOR visibility:public <> ($this:.Z.ENTRY) returnType:.Z.ENTRY.A [primary] $outer: VALUE_PARAMETER name: type:.Z.ENTRY BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any'