From 798a6bf689a1e744865820692e3e7e15ad5b705c Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 21 Oct 2014 17:49:11 +0400 Subject: [PATCH] Temp workaround: force out-of-block modification for properties with nullable types Initializers for properties with nullable types are analyzed with binding context common for all declarations. This can cause invalid elements are left in the cache guarded with out-of-block modification tracker. This workaround forces increment for such cases. --- .../KotlinCodeBlockModificationListener.kt | 5 ----- .../InPropertyWithFunctionLiteral.kt | 2 +- ...otNullType_Initializer_ObjectLiteral_Fun.kt | 10 ++++++++++ .../PropNullType_Initializer_If_Fun.kt | 12 ++++++++++++ ...opNullType_Initializer_ObjectLiteral_Fun.kt | 10 ++++++++++ .../PropertyWithType_Initializer_String.kt | 2 +- .../OutOfBlockModificationTestGenerated.java | 18 ++++++++++++++++++ 7 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 idea/testData/codeInsight/outOfBlock/PropNotNullType_Initializer_ObjectLiteral_Fun.kt create mode 100644 idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_If_Fun.kt create mode 100644 idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_ObjectLiteral_Fun.kt diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt index fcaf8499b79..da577c7b223 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt @@ -125,11 +125,6 @@ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModific } is JetProperty -> { val property = blockDeclarationCandidate : JetProperty - val typeReference = property.getTypeReference() - if (typeReference != null && property.getInitializer().isAncestorOf(element)) { - return true - } - for (accessor in property.getAccessors()) { when { accessor.getInitializer().isAncestorOf(element) -> return true diff --git a/idea/testData/codeInsight/outOfBlock/InPropertyWithFunctionLiteral.kt b/idea/testData/codeInsight/outOfBlock/InPropertyWithFunctionLiteral.kt index 083f7a24071..7a29f2d1c2d 100644 --- a/idea/testData/codeInsight/outOfBlock/InPropertyWithFunctionLiteral.kt +++ b/idea/testData/codeInsight/outOfBlock/InPropertyWithFunctionLiteral.kt @@ -1,4 +1,4 @@ -// FALSE +// TRUE class Test { val a : () -> Int = { pri } } \ No newline at end of file diff --git a/idea/testData/codeInsight/outOfBlock/PropNotNullType_Initializer_ObjectLiteral_Fun.kt b/idea/testData/codeInsight/outOfBlock/PropNotNullType_Initializer_ObjectLiteral_Fun.kt new file mode 100644 index 00000000000..de8927a7da8 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/PropNotNullType_Initializer_ObjectLiteral_Fun.kt @@ -0,0 +1,10 @@ +// TRUE + +// Problem with lazy initialization of nullable properties +trait Some + +val test: Some = object: Some { + fun test() { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_If_Fun.kt b/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_If_Fun.kt new file mode 100644 index 00000000000..89406328014 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_If_Fun.kt @@ -0,0 +1,12 @@ +// TRUE + +// Problem with lazy initialization of nullable properties + +val test: Int? = if (true) { + fun test() { + val t + } +} +else { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_ObjectLiteral_Fun.kt b/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_ObjectLiteral_Fun.kt new file mode 100644 index 00000000000..180d7bfd371 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_ObjectLiteral_Fun.kt @@ -0,0 +1,10 @@ +// TRUE + +// Problem with lazy initialization of nullable properties +trait Some + +val test: Some? = object: Some { + fun test() { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/outOfBlock/PropertyWithType_Initializer_String.kt b/idea/testData/codeInsight/outOfBlock/PropertyWithType_Initializer_String.kt index 259979a5210..d3e072aa7d9 100644 --- a/idea/testData/codeInsight/outOfBlock/PropertyWithType_Initializer_String.kt +++ b/idea/testData/codeInsight/outOfBlock/PropertyWithType_Initializer_String.kt @@ -1,3 +1,3 @@ -// FALSE +// TRUE val test: String = "" \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTestGenerated.java index 0c65ab5d331..8784233334a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTestGenerated.java @@ -192,6 +192,24 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif doTest(fileName); } + @TestMetadata("PropNotNullType_Initializer_ObjectLiteral_Fun.kt") + public void testPropNotNullType_Initializer_ObjectLiteral_Fun() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/PropNotNullType_Initializer_ObjectLiteral_Fun.kt"); + doTest(fileName); + } + + @TestMetadata("PropNullType_Initializer_If_Fun.kt") + public void testPropNullType_Initializer_If_Fun() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_If_Fun.kt"); + doTest(fileName); + } + + @TestMetadata("PropNullType_Initializer_ObjectLiteral_Fun.kt") + public void testPropNullType_Initializer_ObjectLiteral_Fun() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/PropNullType_Initializer_ObjectLiteral_Fun.kt"); + doTest(fileName); + } + @TestMetadata("PropertyNoType_Initializer_String.kt") public void testPropertyNoType_Initializer_String() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/PropertyNoType_Initializer_String.kt");