[K2] Allow using simple boolean expressions in constant position

Such behavior is not the same as in K1, but it is more consistent.

#KT-64400 Fixed
This commit is contained in:
Ivan Kylchik
2023-12-05 16:58:44 +01:00
committed by Space Team
parent 38ea2ce973
commit f8e9e99d87
13 changed files with 129 additions and 40 deletions
@@ -0,0 +1,22 @@
const val INT = 0
const val LONG = 0L
const val compareInt1 = 1 < 2
const val compareInt2 = 1 <= 3
const val compareInt3 = 1 > 4
const val compareInt4 = 1 >= 5
const val compareInt5 = INT < 2
const val compareInt6 = INT <= 3
const val compareInt7 = INT > 4
const val compareInt8 = INT >= 5
const val compareLong1 = 1L < 2L
const val compareLong2 = 1L <= 3L
const val compareLong3 = 1L > 4L
const val compareLong4 = 1L >= 5L
const val compareLong5 = LONG < 2L
const val compareLong6 = LONG <= 3L
const val compareLong7 = LONG > 4L
const val compareLong8 = LONG >= 5L
@@ -0,0 +1,22 @@
const val INT = 0
const val LONG = 0L
const val compareInt1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1 < 2<!>
const val compareInt2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1 <= 3<!>
const val compareInt3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1 > 4<!>
const val compareInt4 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1 >= 5<!>
const val compareInt5 = INT < 2
const val compareInt6 = INT <= 3
const val compareInt7 = INT > 4
const val compareInt8 = INT >= 5
const val compareLong1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L < 2L<!>
const val compareLong2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L <= 3L<!>
const val compareLong3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L > 4L<!>
const val compareLong4 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L >= 5L<!>
const val compareLong5 = LONG < 2L
const val compareLong6 = LONG <= 3L
const val compareLong7 = LONG > 4L
const val compareLong8 = LONG >= 5L
@@ -0,0 +1,46 @@
// !LANGUAGE: -IntrinsicConstEvaluation
const val equalsBoolean1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>true.equals(true)<!>
const val equalsBoolean2 = false != true
const val equalsBoolean3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>false.equals(1)<!>
const val equalsBoolean4 = <!EQUALITY_NOT_APPLICABLE!>false == 1<!>
const val equalsChar1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>'1'.equals('2')<!>
const val equalsChar2 = '2' == '2'
const val equalsChar3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>'1'.equals(1)<!>
const val equalsChar4 = <!EQUALITY_NOT_APPLICABLE!>'1' == 1<!>
const val equalsByte1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.toByte().equals(2.toByte())<!>
const val equalsByte2 = 2.toByte() == 2.toByte()
const val equalsByte3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.toByte().equals("1")<!>
const val equalsByte4 = <!EQUALITY_NOT_APPLICABLE!>1.toByte() == "1"<!>
const val equalsShort1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.toShort().equals(2.toShort())<!>
const val equalsShort2 = 2.toShort() == 2.toShort()
const val equalsShort3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.toShort().equals("1")<!>
const val equalsShort4 = <!EQUALITY_NOT_APPLICABLE!>1.toShort() == "1"<!>
const val equalsInt1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.equals(2)<!>
const val equalsInt2 = 2 == 2
const val equalsInt3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.equals("1")<!>
const val equalsInt4 = <!EQUALITY_NOT_APPLICABLE!>1 == "1"<!>
const val equalsLong1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L.equals(2L)<!>
const val equalsLong2 = 2L == 2L
const val equalsLong3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1L.equals("1")<!>
const val equalsLong4 = <!EQUALITY_NOT_APPLICABLE!>1L == "1"<!>
const val equalsFloat1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.0f.equals(2.0f)<!>
const val equalsFloat2 = 2.0f == 2.0f
const val equalsFloat3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.0f.equals("1")<!>
const val equalsFloat4 = <!EQUALITY_NOT_APPLICABLE!>1.0f == "1"<!>
const val equalsDoable1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.0.equals(2.0)<!>
const val equalsDoable2 = 2.0 == 2.0
const val equalsDoable3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>1.0.equals("1")<!>
const val equalsDoable4 = <!EQUALITY_NOT_APPLICABLE!>1.0 == "1"<!>
const val equalsString1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>"someStr".equals("123")<!>
const val equalsString2 = "someStr" == "otherStr"
const val equalsString3 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>"someStr".equals(1)<!>
const val equalsString4 = <!EQUALITY_NOT_APPLICABLE!>"someStr" == 1<!>
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !LANGUAGE: -IntrinsicConstEvaluation
const val equalsBoolean1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>true.equals(true)<!>
@@ -0,0 +1,3 @@
// ISSUE: KT-55196
const val bb: Boolean = !false // Red in K1, green in K2
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// ISSUE: KT-55196
const val bb: Boolean = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>!false<!> // Red in K1, green in K2