From 10d16d10d5965287102aceee32304a6a858d117e Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Tue, 16 Mar 2021 11:16:00 +0000 Subject: [PATCH] Raw FIR: Fix downward propagation of `external` and `inline` from property to default accessors for light-tree. --- ...tionArgumentKClassLiteralTypeError.fir.txt | 2 +- .../converter/DeclarationsConverter.kt | 16 +++++++----- ...ghtTree2FirConverterTestCaseGenerated.java | 5 ++++ .../rawBuilder/declarations/external.kt | 16 ++++++++++++ .../declarations/external.lazyBodies.txt | 25 ++++++++++++++++++ .../rawBuilder/declarations/external.txt | 26 +++++++++++++++++++ ...FirBuilderLazyBodiesTestCaseGenerated.java | 5 ++++ .../RawFirBuilderTestCaseGenerated.java | 5 ++++ .../org/jetbrains/kotlin/fir/FirRenderer.kt | 8 +++--- .../FirVisualizerForRawFirDataGenerated.java | 5 ++++ .../PsiVisualizerForRawFirDataGenerated.java | 5 ++++ 11 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt create mode 100644 compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.lazyBodies.txt create mode 100644 compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationArgumentKClassLiteralTypeError.fir.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationArgumentKClassLiteralTypeError.fir.txt index 5d037b7f706..e9ac47ae1b4 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationArgumentKClassLiteralTypeError.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationArgumentKClassLiteralTypeError.fir.txt @@ -9,7 +9,7 @@ FILE: annotationArgumentKClassLiteralTypeError.kt } public final val R|T|.test: R|kotlin/Any| - public get(): R|| { + public inline get(): R|| { ^ @R|Ann|(((R|T|), (Q|kotlin/Array|))) object : R|kotlin/Any| { private constructor(): R|| { super() diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index 74899c371ba..b0679a4d83a 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -40,8 +40,6 @@ import org.jetbrains.kotlin.fir.lightTree.fir.modifier.TypeProjectionModifier import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.references.impl.FirReferencePlaceholderForResolvedAnnotations import org.jetbrains.kotlin.fir.scopes.FirScopeProvider -import org.jetbrains.kotlin.name.CallableId -import org.jetbrains.kotlin.name.LocalCallableIdConstructor import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.* @@ -50,10 +48,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens.* -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.name.SpecialNames +import org.jetbrains.kotlin.name.* import org.jetbrains.kotlin.utils.addToStdlib.runIf class DeclarationsConverter( @@ -1009,11 +1004,19 @@ class DeclarationsConverter( val propertyVisibility = modifiers.getVisibility() + fun defaultAccessorStatus() = + // Downward propagation of `inline` and `external` modifiers (from property to its accessors) + FirDeclarationStatusImpl(propertyVisibility, modifiers.getModality()).apply { + isInline = modifiers.hasInline() + isExternal = modifiers.hasExternal() + } + val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, modifiers) } this.getter = convertedAccessors.find { it.isGetter } ?: FirDefaultPropertyGetter( null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility ).also { + it.status = defaultAccessorStatus() currentDispatchReceiverType()?.lookupTag?.let { lookupTag -> it.containingClassAttr = lookupTag } @@ -1024,6 +1027,7 @@ class DeclarationsConverter( FirDefaultPropertySetter( null, session, FirDeclarationOrigin.Source, returnType, propertyVisibility ).also { + it.status = defaultAccessorStatus() currentDispatchReceiverType()?.lookupTag?.let { lookupTag -> it.containingClassAttr = lookupTag } diff --git a/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java b/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java index a4cc0132c4b..ad1a65ea2fa 100644 --- a/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java +++ b/compiler/fir/raw-fir/light-tree2fir/tests-gen/org/jetbrains/kotlin/fir/lightTree/LightTree2FirConverterTestCaseGenerated.java @@ -91,6 +91,11 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("external.kt") + public void testExternal() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); + } + @TestMetadata("F.kt") public void testF() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/F.kt"); diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt new file mode 100644 index 00000000000..8975dfc32a9 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt @@ -0,0 +1,16 @@ +external class External + +external fun foo(): String + +external val x: Int + +class NotExternal { + external fun bar(): String + var y: Int + external get + set(value) {} +} + +var z: Int + external get + external set diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.lazyBodies.txt new file mode 100644 index 00000000000..464c7064a50 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.lazyBodies.txt @@ -0,0 +1,25 @@ +FILE: external.kt + public? final? external class External : R|kotlin/Any| { + public? constructor(): R|External| { + super() + } + + } + public? final? external fun foo(): String + public? final? external val x: Int + public? external get(): Int + public? final? class NotExternal : R|kotlin/Any| { + public? constructor(): R|NotExternal| { + super() + } + + public? final? external fun bar(): String + + public? final? var y: Int + public? external get(): Int + public? set(value: Int): R|kotlin/Unit| { LAZY_BLOCK } + + } + public? final? external var z: Int + public? external get(): Int + public? external set(value: Int): R|kotlin/Unit| diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.txt new file mode 100644 index 00000000000..8c13828c075 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.txt @@ -0,0 +1,26 @@ +FILE: external.kt + public? final? external class External : R|kotlin/Any| { + public? constructor(): R|External| { + super() + } + + } + public? final? external fun foo(): String + public? final? external val x: Int + public? external get(): Int + public? final? class NotExternal : R|kotlin/Any| { + public? constructor(): R|NotExternal| { + super() + } + + public? final? external fun bar(): String + + public? final? var y: Int + public? external get(): Int + public? set(value: Int): R|kotlin/Unit| { + } + + } + public? final? external var z: Int + public? external get(): Int + public? external set(value: Int): R|kotlin/Unit| diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java index 3eeef1dfd60..262cd726b0f 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java @@ -91,6 +91,11 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("external.kt") + public void testExternal() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); + } + @TestMetadata("F.kt") public void testF() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/F.kt"); diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java index 14eb5f55b6d..e9d32f6c489 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java @@ -91,6 +91,11 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("external.kt") + public void testExternal() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); + } + @TestMetadata("F.kt") public void testF() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/F.kt"); diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index d14e48726ef..c1f73abe8bb 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -295,6 +295,9 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM if (memberDeclaration.isActual) { print("actual ") } + if (memberDeclaration.isExternal) { + print("external ") + } if (memberDeclaration is FirCallableMemberDeclaration<*>) { if (memberDeclaration.isOverride) { print("override ") @@ -329,9 +332,6 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM if (memberDeclaration.isTailRec) { print("tailrec ") } - if (memberDeclaration.isExternal) { - print("external ") - } if (memberDeclaration.isSuspend) { print("suspend ") } @@ -514,6 +514,8 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM propertyAccessor.renderPhaseIfNeeded() propertyAccessor.annotations.renderAnnotations() print(propertyAccessor.visibility.asString() + " ") + print(if (propertyAccessor.isInline) "inline " else "") + print(if (propertyAccessor.isExternal) "external " else "") print(if (propertyAccessor.isGetter) "get" else "set") propertyAccessor.valueParameters.renderParameters() print(": ") diff --git a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java index 6e417ac5056..53a4a1a5964 100644 --- a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java +++ b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/fir/FirVisualizerForRawFirDataGenerated.java @@ -91,6 +91,11 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizer { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("external.kt") + public void testExternal() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); + } + @TestMetadata("F.kt") public void testF() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/F.kt"); diff --git a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java index 8d27957c8ad..7c5b81ecbeb 100644 --- a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java +++ b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/psi/PsiVisualizerForRawFirDataGenerated.java @@ -91,6 +91,11 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizer { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt"); } + @TestMetadata("external.kt") + public void testExternal() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt"); + } + @TestMetadata("F.kt") public void testF() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/F.kt");