FIR: don't report CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT on variables
This commit is contained in:
+1
-1
@@ -38,5 +38,5 @@ object F {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
<!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT!>const<!> val a = "2"
|
const val a = "2"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -12,13 +12,11 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.fir.declarations.isConst
|
||||||
|
|
||||||
object FirConstPropertyChecker : FirPropertyChecker() {
|
object FirConstPropertyChecker : FirPropertyChecker() {
|
||||||
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
val modifierList = with(FirModifierList) { declaration.source.getModifierList() }
|
if (!declaration.isConst) return
|
||||||
if (modifierList?.modifiers?.any { it.token == KtTokens.CONST_KEYWORD } != true)
|
|
||||||
return
|
|
||||||
val classKind = (context.containingDeclarations.lastOrNull() as? FirRegularClass)?.classKind
|
val classKind = (context.containingDeclarations.lastOrNull() as? FirRegularClass)?.classKind
|
||||||
if (classKind != ClassKind.OBJECT && context.containingDeclarations.size > 1)
|
if (classKind != ClassKind.OBJECT && context.containingDeclarations.size > 1)
|
||||||
reporter.reportOn(declaration.source, FirErrors.CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, context)
|
reporter.reportOn(declaration.source, FirErrors.CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, context)
|
||||||
|
|||||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ fun test() {
|
|||||||
val <T> a0 = 0
|
val <T> a0 = 0
|
||||||
val <T : __UNRESOLVED__> a1 = ""
|
val <T : __UNRESOLVED__> a1 = ""
|
||||||
val <T : String> a2 = 0
|
val <T : String> a2 = 0
|
||||||
<!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT!>const<!> val <T> a3 = 0
|
const val <T> a3 = 0
|
||||||
<!INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <T> a4 = 0
|
<!INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <T> a4 = 0
|
||||||
val <T> a5 by Delegate<Int>()
|
val <T> a5 by Delegate<Int>()
|
||||||
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<!><<!UNRESOLVED_REFERENCE!>T<!>>()
|
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<!><<!UNRESOLVED_REFERENCE!>T<!>>()
|
||||||
|
|||||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ fun test() {
|
|||||||
val <T> a0 = 0
|
val <T> a0 = 0
|
||||||
val <T : __UNRESOLVED__> a1 = ""
|
val <T : __UNRESOLVED__> a1 = ""
|
||||||
val <T : String> a2 = 0
|
val <T : String> a2 = 0
|
||||||
<!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT!>const<!> val <T> a3 = 0
|
const val <T> a3 = 0
|
||||||
<!INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <T> a4 = 0
|
<!INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <T> a4 = 0
|
||||||
val <T> a5 by Delegate<Int>()
|
val <T> a5 by Delegate<Int>()
|
||||||
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<!><<!UNRESOLVED_REFERENCE!>T<!>>()
|
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<!><<!UNRESOLVED_REFERENCE!>T<!>>()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ object A {
|
|||||||
const val inObject: Int = 4
|
const val inObject: Int = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
class B(<!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT!>const<!> val constructor: Int = 5)
|
class B(const val constructor: Int = 5)
|
||||||
|
|
||||||
abstract class C {
|
abstract class C {
|
||||||
<!INCOMPATIBLE_MODIFIERS!>open<!> <!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, INCOMPATIBLE_MODIFIERS!>const<!> val x: Int = 6
|
<!INCOMPATIBLE_MODIFIERS!>open<!> <!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, INCOMPATIBLE_MODIFIERS!>const<!> val x: Int = 6
|
||||||
@@ -48,7 +48,7 @@ const val withExplicitDefaultGetter: Int = 1
|
|||||||
get
|
get
|
||||||
|
|
||||||
fun foo(): Int {
|
fun foo(): Int {
|
||||||
<!CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT!>const<!> val local: Int = 14
|
const val local: Int = 14
|
||||||
return 15
|
return 15
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user