FIR: introduce three diagnostics for const val

This commit is contained in:
zadorotskas
2021-03-05 12:51:26 +03:00
committed by Mikhail Glukhikh
parent cc106085e2
commit 334d0a8b5a
23 changed files with 451 additions and 200 deletions
@@ -0,0 +1,36 @@
// FILE: Constants.java
public class Constants {
public static final String FIRST = "1st";
public static final String SECOND = "2nd";
}
// FILE: const.kt
const val a = "something"
<!MUST_BE_INITIALIZED!><!CONST_VAL_WITHOUT_INITIALIZER!>const<!> val b<!>
<!TYPE_CANT_BE_USED_FOR_CONST_VAL!>const<!> val c = null
<!TYPE_CANT_BE_USED_FOR_CONST_VAL!>const<!> val d = ForConst
const val e = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>ForConst.one()<!>
const val f = ((1 + 2) * 3) / 4 % 5 - 1
const val g = "string $f"
const val h = "string" + g
const val i = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>ForConst.one() + "one"<!>
const val j = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>4 * ForConst.two()<!>
val k = 3 - ForConst.two()
const val l = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>k<!>
class ForConst{
companion object {
fun one(): String = "1"
fun two(): Int = 2
}
}
private const val MAJOR_BITS = 3
private const val MINOR_BITS = 4
private const val PATCH_BITS = 7
private const val MAJOR_MASK = (1 shl MAJOR_BITS) - 1 // False positive error
private const val MINOR_MASK = (1 shl MINOR_BITS) - 1 // False positive error
private const val PATCH_MASK = (1 shl PATCH_BITS) - 1 // False positive error
private const val stringFromJava = Constants.FIRST + "+" + Constants.SECOND