Skip to content

Commit ecfc223

Browse files
committed
Fix script properties kind in modifier checker #KT-18234 Fixed
1 parent 29f25eb commit ecfc223

File tree

7 files changed

+46
-2
lines changed

7 files changed

+46
-2
lines changed

compiler/frontend/src/org/jetbrains/kotlin/psi/KtProperty.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ public boolean isVar() {
6868
}
6969

7070
public boolean isLocal() {
71+
return !isTopLevel() && !isMember();
72+
}
73+
74+
public boolean isMember() {
7175
PsiElement parent = getParent();
72-
return !(parent instanceof KtFile || parent instanceof KtClassBody);
76+
return parent instanceof KtClassOrObject || parent instanceof KtClassBody ||
77+
parent instanceof KtBlockExpression && parent.getParent() instanceof KtScript;
7378
}
7479

7580
public boolean isTopLevel() {

compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class AnnotationChecker(private val additionalCheckers: Iterable<AdditionalAnnot
204204
is KtProperty -> {
205205
if (annotated.isLocal)
206206
TargetLists.T_LOCAL_VARIABLE
207-
else if (annotated.parent is KtClassOrObject || annotated.parent is KtClassBody)
207+
else if (annotated.isMember)
208208
TargetLists.T_MEMBER_PROPERTY(descriptor.hasBackingField(trace), annotated.hasDelegate())
209209
else
210210
TargetLists.T_TOP_LEVEL_PROPERTY(descriptor.hasBackingField(trace), annotated.hasDelegate())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lateinit var s: String
2+
3+
fun foo() {
4+
s = "Hello"
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package
2+
3+
public final class LateInit : kotlin.script.templates.standard.ScriptTemplateWithArgs {
4+
public constructor LateInit(/*0*/ args: kotlin.Array<kotlin.String>)
5+
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
6+
public final lateinit var s: kotlin.String
7+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
8+
public final fun foo(): kotlin.Unit
9+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
10+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
private val s = "Hello"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package
2+
3+
public final class PrivateVal : kotlin.script.templates.standard.ScriptTemplateWithArgs {
4+
public constructor PrivateVal(/*0*/ args: kotlin.Array<kotlin.String>)
5+
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
6+
private final val s: kotlin.String = "Hello"
7+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
8+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
9+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
10+
}

compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23642,12 +23642,24 @@ public void testImports() throws Exception {
2364223642
doTest(fileName);
2364323643
}
2364423644

23645+
@TestMetadata("LateInit.kts")
23646+
public void testLateInit() throws Exception {
23647+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/LateInit.kts");
23648+
doTest(fileName);
23649+
}
23650+
2364523651
@TestMetadata("NestedInnerClass.kts")
2364623652
public void testNestedInnerClass() throws Exception {
2364723653
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/NestedInnerClass.kts");
2364823654
doTest(fileName);
2364923655
}
2365023656

23657+
@TestMetadata("PrivateVal.kts")
23658+
public void testPrivateVal() throws Exception {
23659+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/PrivateVal.kts");
23660+
doTest(fileName);
23661+
}
23662+
2365123663
@TestMetadata("resolveInitializerOfDestructuringDeclarationOnce.kts")
2365223664
public void testResolveInitializerOfDestructuringDeclarationOnce() throws Exception {
2365323665
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/resolveInitializerOfDestructuringDeclarationOnce.kts");

0 commit comments

Comments
 (0)