Report initializer block-related diagnostic on 'init' keyword
This commit is contained in:
@@ -810,7 +810,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtDeclarationWithBody>
|
||||
NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_WITH_BODY);
|
||||
|
||||
DiagnosticFactory0<KtAnonymousInitializer> ANONYMOUS_INITIALIZER_IN_INTERFACE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtAnonymousInitializer> ANONYMOUS_INITIALIZER_IN_INTERFACE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<KtThisExpression> NO_THIS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<KtSimpleNameExpression, ClassifierDescriptor> NO_COMPANION_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
@@ -160,6 +160,9 @@ object PositioningStrategies {
|
||||
is KtObjectDeclaration -> {
|
||||
return DECLARATION_NAME.mark(element)
|
||||
}
|
||||
is KtClassInitializer -> {
|
||||
return markRange(element.initKeyword.textRange)
|
||||
}
|
||||
}
|
||||
return super.mark(element)
|
||||
}
|
||||
|
||||
@@ -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<KotlinPlaceHolderStub<KtClassInitia
|
||||
val openBraceNode: PsiElement?
|
||||
get() = (body as? KtBlockExpression)?.lBrace
|
||||
|
||||
val initKeyword: PsiElement
|
||||
get() = findChildByType(KtTokens.INIT_KEYWORD)!!
|
||||
|
||||
override val containingDeclaration: KtDeclaration
|
||||
get() = getParentOfType<KtClassOrObject>(true).sure { "Should only be present in class or object" }
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
interface NoC {
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init {
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init<!> {
|
||||
|
||||
}<!>
|
||||
}
|
||||
|
||||
val a : Int get() = 1
|
||||
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init {
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init<!> {
|
||||
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
class WithC() {
|
||||
@@ -23,4 +23,4 @@ class WithC() {
|
||||
val <!UNUSED_VARIABLE!>z<!> = <!UNRESOLVED_REFERENCE!>b<!>
|
||||
val <!UNUSED_VARIABLE!>zz<!> = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ class A {
|
||||
}
|
||||
|
||||
interface T {
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!><!WRONG_ANNOTATION_TARGET!>@ann<!> init {}<!>
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!><!WRONG_ANNOTATION_TARGET!>@<!UNRESOLVED_REFERENCE!>aaa<!><!> init {}<!>
|
||||
<!WRONG_ANNOTATION_TARGET!>@ann<!> <!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init<!> {}
|
||||
<!WRONG_ANNOTATION_TARGET!>@<!UNRESOLVED_REFERENCE!>aaa<!><!> <!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init<!> {}
|
||||
}
|
||||
|
||||
annotation class ann
|
||||
annotation class ann
|
||||
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
interface NoC {
|
||||
<error>init {
|
||||
<error>init</error> {
|
||||
|
||||
}</error>
|
||||
}
|
||||
|
||||
val a : Int get() = 1
|
||||
|
||||
<error>init {
|
||||
<error>init</error> {
|
||||
|
||||
}</error>
|
||||
}
|
||||
}
|
||||
|
||||
class WithC() {
|
||||
@@ -24,4 +24,4 @@ class WithC() {
|
||||
val <warning>zz</warning> = x
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
interface I {
|
||||
<error>init {
|
||||
<error>init</error> {
|
||||
val c = 1
|
||||
val g = c
|
||||
}</error>
|
||||
}
|
||||
val <warning>g</warning> = c
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user