diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 2c96bc0a789..835f63b119e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -810,7 +810,7 @@ public interface Errors { DiagnosticFactory0 NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_WITH_BODY); - DiagnosticFactory0 ANONYMOUS_INITIALIZER_IN_INTERFACE = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 ANONYMOUS_INITIALIZER_IN_INTERFACE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 NO_THIS = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 NO_COMPANION_OBJECT = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index b2d7bedaebf..80f2c63bd1f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -160,6 +160,9 @@ object PositioningStrategies { is KtObjectDeclaration -> { return DECLARATION_NAME.mark(element) } + is KtClassInitializer -> { + return markRange(element.initKeyword.textRange) + } } return super.mark(element) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnonymousInitializer.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnonymousInitializer.kt index 5ef304cfaa8..b555d11529c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnonymousInitializer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtAnonymousInitializer.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.psi import com.intellij.lang.ASTNode import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes @@ -41,6 +42,9 @@ class KtClassInitializer : KtDeclarationStub(true).sure { "Should only be present in class or object" } } diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt index 0d8269ae8fa..71247bc67bf 100644 --- a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt +++ b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt @@ -1,13 +1,13 @@ interface NoC { - init { + init { - } + } val a : Int get() = 1 - init { + init { - } + } } class WithC() { @@ -23,4 +23,4 @@ class WithC() { val z = b val zz = x } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt index 9da6d3d8d8a..355fdd3cec3 100644 --- a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt +++ b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt @@ -4,8 +4,8 @@ class A { } interface T { - @ann init {} - @aaa init {} + @ann init {} + @aaa init {} } -annotation class ann \ No newline at end of file +annotation class ann diff --git a/idea/testData/checker/AnonymousInitializers.kt b/idea/testData/checker/AnonymousInitializers.kt index 7adf0b316d5..9c4f52d8e08 100644 --- a/idea/testData/checker/AnonymousInitializers.kt +++ b/idea/testData/checker/AnonymousInitializers.kt @@ -1,13 +1,13 @@ interface NoC { - init { + init { - } + } val a : Int get() = 1 - init { + init { - } + } } class WithC() { @@ -24,4 +24,4 @@ class WithC() { val zz = x } -} \ No newline at end of file +} diff --git a/idea/testData/checker/regression/InitializerInInterface.kt b/idea/testData/checker/regression/InitializerInInterface.kt index c2ad3ee9ba8..38070da0fec 100644 --- a/idea/testData/checker/regression/InitializerInInterface.kt +++ b/idea/testData/checker/regression/InitializerInInterface.kt @@ -1,6 +1,6 @@ interface I { - init { + init { val c = 1 - val g = c - } -} \ No newline at end of file + val g = c + } +}