Files
kotlin/compiler/testData/diagnostics/tests/modifiers/const/constInteraction.kt
Denis Zharkov b2b76d16d0 Add checks for const modifier applicability
1. Must be initialized in-place
2. Can not be open/abstract
3. Can not be an override
4. Can not be delegated
5. Initializer must be a compile-time constant
6. No getters
7. `const` is not applicable to vars or locals
8. `const val` should be whether top-level property or object member
2015-09-23 08:20:56 +03:00

19 lines
489 B
Kotlin
Vendored

const val aConst = 1
const val bConst = aConst + 1
const val boolVal = bConst > 1 || (B.boolVal && A.boolVal)
const val stringInterpolation = "Result: ${B.boolVal}"
object A {
const val boolVal = bConst + 3 == 5
const val recursive1: Int = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1 + B.recursive2<!>
}
class B {
companion object {
const val boolVal = A.boolVal
const val recursive2: Int = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>A.recursive1 + 2<!>
}
}