From 4e76975a5242c1422e26b4a5426d5bcaac3ea2ab Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 17 Jul 2017 22:14:24 +0300 Subject: [PATCH] Force OOB in accessors for properties without explicit type (KT-19062) #KT-19062 Fixed --- .../project/KotlinCodeBlockModificationListener.kt | 10 ++++++---- .../InPropertyAccessorWithInferenceInClass.kt | 12 ++++++++++++ .../OutOfBlockModificationTestGenerated.java | 6 ++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 idea/testData/codeInsight/outOfBlock/InPropertyAccessorWithInferenceInClass.kt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/KotlinCodeBlockModificationListener.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/KotlinCodeBlockModificationListener.kt index dc9ddb5a698..ae574a27747 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/KotlinCodeBlockModificationListener.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/KotlinCodeBlockModificationListener.kt @@ -89,10 +89,12 @@ class KotlinCodeBlockModificationListener( } is KtProperty -> { - for (accessor in blockDeclaration.accessors) { - (accessor.initializer ?: accessor.bodyExpression) - ?.takeIf { it.isAncestor(element) } - ?.let { return it } + if (blockDeclaration.typeReference != null) { + for (accessor in blockDeclaration.accessors) { + (accessor.initializer ?: accessor.bodyExpression) + ?.takeIf { it.isAncestor(element) } + ?.let { return it } + } } } diff --git a/idea/testData/codeInsight/outOfBlock/InPropertyAccessorWithInferenceInClass.kt b/idea/testData/codeInsight/outOfBlock/InPropertyAccessorWithInferenceInClass.kt new file mode 100644 index 00000000000..5b91116857b --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/InPropertyAccessorWithInferenceInClass.kt @@ -0,0 +1,12 @@ +// TRUE + +class A { + fun foo(): Int = 12 +} + +class B(val a: A) { + val prop1 get() = a.foo() +} + +// TODO +// SKIP_ANALYZE_CHECK \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java index 8c0315a1f1c..42cc24bf2c9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java @@ -180,6 +180,12 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif doTest(fileName); } + @TestMetadata("InPropertyAccessorWithInferenceInClass.kt") + public void testInPropertyAccessorWithInferenceInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/InPropertyAccessorWithInferenceInClass.kt"); + doTest(fileName); + } + @TestMetadata("InPropertyWithFunctionLiteral.kt") public void testInPropertyWithFunctionLiteral() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/InPropertyWithFunctionLiteral.kt");