From 9e30ede998ac3033d3fe915d109f6215159d1d4d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 21 Feb 2018 10:13:08 +0100 Subject: [PATCH] Fix ISE in KotlinPairMatcher.getCodeConstructStart() --- idea/src/org/jetbrains/kotlin/idea/KotlinPairMatcher.kt | 4 +++- .../kotlin/idea/codeInsight/KotlinPairMatcherTest.kt | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/KotlinPairMatcher.kt b/idea/src/org/jetbrains/kotlin/idea/KotlinPairMatcher.kt index 8ea3290589d..2231a5c15e5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/KotlinPairMatcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/KotlinPairMatcher.kt @@ -44,7 +44,9 @@ class KotlinPairMatcher : PairedBraceMatcher { if (element == null || element is PsiFile) return openingBraceOffset val parent = element.parent return when (parent) { - is KtClassBody, is KtBlockExpression -> DeclarationRangeUtil.getDeclarationRange(parent.parent).startOffset + is KtClassBody, is KtBlockExpression -> + DeclarationRangeUtil.getPossibleDeclarationAtRange(parent.parent)?.startOffset ?: openingBraceOffset + else -> openingBraceOffset } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/KotlinPairMatcherTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/KotlinPairMatcherTest.kt index e7f07d6987e..385c317c50e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/KotlinPairMatcherTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/KotlinPairMatcherTest.kt @@ -38,4 +38,8 @@ class KotlinPairMatcherTest : KotlinLightCodeInsightFixtureTestCase() { fun testFun() { doTest("/* Doc comment */ fun xyzzy(x: Int, y: String): Any { }") } + + fun testFor() { + doTest("fun xyzzy() { for (x in 0..1){ } }") + } }