From 1d88c307ea248a96f3d5fed723d658f3bedeeb9f Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 15 Jun 2023 11:48:28 +0200 Subject: [PATCH] K2 Scripting: fix locality of script declarations the script declarations are considered public, at least because they can be reused from another script then used with the `importedScripts` configuration property. It also improves the compatibility with K1 scripting. --- .../kotlin/fir/builder/PsiConversionUtils.kt | 2 +- .../jetbrains/kotlin/psi/KtNamedFunction.java | 2 +- .../destructuringDeclaration.fir.ir.txt | 20 +++++++++---------- .../kotlin/mainKts/test/mainKtsTest.kt | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt index 94482502a53..b429c3b0901 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt @@ -152,7 +152,7 @@ internal fun generateDestructuringBlock( } this.isVar = isVar isLocal = localEntries - status = FirDeclarationStatusImpl(Visibilities.Local, Modality.FINAL) + status = FirDeclarationStatusImpl(if (localEntries) Visibilities.Local else Visibilities.Public, Modality.FINAL) symbol = FirPropertySymbol(name) entry.extractAnnotationsTo(this) } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java index 1a816eb5e84..0e1d4e471da 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java @@ -247,7 +247,7 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub fileName:/destructuringDeclaration.kts SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:def type:kotlin.Int visibility:private [final]' type=kotlin.Unit origin=null value: CALL 'public final fun component2 (): kotlin.Int declared in ..A' type=kotlin.Int origin=COMPONENT_N(index=2) $this: GET_VAR 'val tmp_0: ..A declared in .' type=..A origin=null - PROPERTY name:abc visibility:local modality:FINAL [val] + PROPERTY name:abc visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:abc type:kotlin.Int visibility:private [final] - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:local modality:FINAL <> () returnType:kotlin.Int - correspondingProperty: PROPERTY name:abc visibility:local modality:FINAL [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Int + correspondingProperty: PROPERTY name:abc visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .' + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:abc type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null - PROPERTY name:def visibility:local modality:FINAL [val] + PROPERTY name:def visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:def type:kotlin.Int visibility:private [final] - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:local modality:FINAL <> () returnType:kotlin.Int - correspondingProperty: PROPERTY name:def visibility:local modality:FINAL [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Int + correspondingProperty: PROPERTY name:def visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .' + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:def type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null PROPERTY name:rv visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:rv type:kotlin.Int visibility:private [final] EXPRESSION_BODY CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=PLUS - $this: CALL 'local final fun (): kotlin.Int declared in .' type=kotlin.Int origin=GET_PROPERTY - other: CALL 'local final fun (): kotlin.Int declared in .' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public final fun (): kotlin.Int declared in .' type=kotlin.Int origin=GET_PROPERTY + other: CALL 'public final fun (): kotlin.Int declared in .' type=kotlin.Int origin=GET_PROPERTY FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Int correspondingProperty: PROPERTY name:rv visibility:public modality:FINAL [val] BLOCK_BODY diff --git a/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsTest.kt b/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsTest.kt index 2ea45bdc25b..cebf019a4f7 100644 --- a/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsTest.kt +++ b/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsTest.kt @@ -205,7 +205,7 @@ class MainKtsTest { } @Test - fun testScriptFileLocationWithImportedScript() = expectTestToFailOnK2 { + fun testScriptFileLocationWithImportedScript() { val resOk = evalFile(File("$TEST_DATA_ROOT/script-file-location-with-imported-file.main.kts")) assertSucceeded(resOk) val resultValue = resOk.valueOrThrow().returnValue