Skip to content

Commit 8068a54

Browse files
vladimirdolzhenkoSpace
authored andcommitted
Fix handling non ctor elements in SECONDARY_CONSTRUCTOR_DELEGATION_CALL
#KT-45339 Fixed
1 parent 3d236b7 commit 8068a54

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.KtNodeTypes
1515
import org.jetbrains.kotlin.cfg.UnreachableCode
1616
import org.jetbrains.kotlin.diagnostics.Errors.ACTUAL_WITHOUT_EXPECT
1717
import org.jetbrains.kotlin.diagnostics.Errors.NO_ACTUAL_FOR_EXPECT
18-
import org.jetbrains.kotlin.diagnostics.PositioningStrategies.INNER_MODIFIER
1918
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
2019
import org.jetbrains.kotlin.lexer.KtTokens
2120
import org.jetbrains.kotlin.lexer.KtTokens.MODALITY_MODIFIERS
@@ -637,10 +636,10 @@ object PositioningStrategies {
637636
val SECONDARY_CONSTRUCTOR_DELEGATION_CALL: PositioningStrategy<PsiElement> =
638637
object : PositioningStrategy<PsiElement>() {
639638
override fun mark(element: PsiElement): List<TextRange> {
640-
when (element) {
639+
return when (element) {
641640
is KtSecondaryConstructor -> {
642641
val valueParameterList = element.valueParameterList ?: return markElement(element)
643-
return markRange(element.getConstructorKeyword(), valueParameterList.lastChild)
642+
markRange(element.getConstructorKeyword(), valueParameterList.lastChild)
644643
}
645644
is KtConstructorDelegationCall -> {
646645
if (element.isImplicit) {
@@ -650,9 +649,9 @@ object PositioningStrategies {
650649
val valueParameterList = constructor.valueParameterList ?: return markElement(constructor)
651650
return markRange(constructor.getConstructorKeyword(), valueParameterList.lastChild)
652651
}
653-
return markElement(element.calleeExpression ?: element)
652+
markElement(element.calleeExpression ?: element)
654653
}
655-
else -> error("unexpected element $element")
654+
else -> markElement(element)
656655
}
657656
}
658657
}

idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/FirHighlightingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

idea/performanceTests/test/org/jetbrains/kotlin/idea/perf/PerformanceHighlightingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// IGNORE_FIR
2+
3+
interface <info textAttributesKey="KOTLIN_TRAIT">Zoo</info><<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>> {
4+
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION"><error descr="[WRONG_MODIFIER_TARGET] Modifier 'inner' is not applicable to 'enum class'" textAttributesKey="ERRORS_ATTRIBUTES">inner</error></info> <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">enum</info> class <info textAttributesKey="KOTLIN_ENUM">Var</info> : <info textAttributesKey="KOTLIN_TRAIT">Zoo</info><<error descr="[INACCESSIBLE_OUTER_CLASS_EXPRESSION] Expression is inaccessible from a nested class 'Var'" textAttributesKey="ERRORS_ATTRIBUTES">T</error>>
5+
}
6+
7+
object <info textAttributesKey="KOTLIN_OBJECT">Outer</info> {
8+
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">bar</info>() = <info textAttributesKey="KOTLIN_OBJECT">Unit</info>
9+
class <info textAttributesKey="KOTLIN_CLASS">Inner</info> {
10+
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>() = this<info textAttributesKey="KOTLIN_LABEL"><error descr="[INACCESSIBLE_OUTER_CLASS_EXPRESSION] Expression is inaccessible from a nested class 'Inner'" textAttributesKey="ERRORS_ATTRIBUTES">@Outer</error></info>.<error descr="[DEBUG] Reference is not resolved to anything, but is not marked unresolved" textAttributesKey="KOTLIN_DEBUG_INFO">bar</error>()
11+
}
12+
}

idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)