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.
This commit is contained in:
committed by
Space Team
parent
020a590df7
commit
1d88c307ea
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub<KotlinFunction
|
||||
@Override
|
||||
public boolean isLocal() {
|
||||
PsiElement parent = getParent();
|
||||
return !(parent instanceof KtFile || parent instanceof KtClassBody);
|
||||
return !(parent instanceof KtFile || parent instanceof KtClassBody || parent.getParent() instanceof KtScript);
|
||||
}
|
||||
|
||||
public boolean isAnonymous() {
|
||||
|
||||
@@ -9,26 +9,26 @@ FILE fqName:<root> 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 <root>.<script-destructuringDeclaration.kts>.A' type=kotlin.Int origin=COMPONENT_N(index=2)
|
||||
$this: GET_VAR 'val tmp_0: <root>.<script-destructuringDeclaration.kts>.A declared in <root>.<script-destructuringDeclaration.kts>' type=<root>.<script-destructuringDeclaration.kts>.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:<get-abc> visibility:local modality:FINAL <> () returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:abc visibility:local modality:FINAL [val]
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-abc> 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 <get-abc> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>'
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-abc> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>'
|
||||
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:<get-def> visibility:local modality:FINAL <> () returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:def visibility:local modality:FINAL [val]
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-def> 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 <get-def> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>'
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-def> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>'
|
||||
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 <get-abc> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>' type=kotlin.Int origin=GET_PROPERTY
|
||||
other: CALL 'local final fun <get-def> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>' type=kotlin.Int origin=GET_PROPERTY
|
||||
$this: CALL 'public final fun <get-abc> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>' type=kotlin.Int origin=GET_PROPERTY
|
||||
other: CALL 'public final fun <get-def> (): kotlin.Int declared in <root>.<script-destructuringDeclaration.kts>' type=kotlin.Int origin=GET_PROPERTY
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-rv> visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:rv visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user