[K2] Properly check if binary logical expression is constant
This commit is contained in:
+18
@@ -23951,12 +23951,30 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("binaryLogic.kt")
|
||||
public void testBinaryLogic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/binaryLogic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("compare.kt")
|
||||
public void testCompare() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/compare.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_after.kt")
|
||||
public void testComplexBooleanInStringConcat_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_before.kt")
|
||||
public void testComplexBooleanInStringConcat_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constInteraction.kt")
|
||||
public void testConstInteraction() throws Exception {
|
||||
|
||||
+18
@@ -23951,12 +23951,30 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("binaryLogic.kt")
|
||||
public void testBinaryLogic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/binaryLogic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("compare.kt")
|
||||
public void testCompare() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/compare.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_after.kt")
|
||||
public void testComplexBooleanInStringConcat_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_before.kt")
|
||||
public void testComplexBooleanInStringConcat_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constInteraction.kt")
|
||||
public void testConstInteraction() throws Exception {
|
||||
|
||||
+18
@@ -23945,12 +23945,30 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("binaryLogic.kt")
|
||||
public void testBinaryLogic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/binaryLogic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("compare.kt")
|
||||
public void testCompare() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/compare.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_after.kt")
|
||||
public void testComplexBooleanInStringConcat_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_before.kt")
|
||||
public void testComplexBooleanInStringConcat_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constInteraction.kt")
|
||||
public void testConstInteraction() throws Exception {
|
||||
|
||||
+18
@@ -23951,12 +23951,30 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("binaryLogic.kt")
|
||||
public void testBinaryLogic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/binaryLogic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("compare.kt")
|
||||
public void testCompare() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/compare.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_after.kt")
|
||||
public void testComplexBooleanInStringConcat_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_before.kt")
|
||||
public void testComplexBooleanInStringConcat_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constInteraction.kt")
|
||||
public void testConstInteraction() throws Exception {
|
||||
|
||||
@@ -103,6 +103,10 @@ internal fun checkConstantArguments(
|
||||
checkConstantArguments(exp, session)?.let { return it }
|
||||
}
|
||||
}
|
||||
expression is FirBinaryLogicExpression -> {
|
||||
checkConstantArguments(expression.leftOperand, session)?.let { return it }
|
||||
checkConstantArguments(expression.rightOperand, session)?.let { return it }
|
||||
}
|
||||
expression is FirGetClassCall -> {
|
||||
var coneType = (expression as? FirCall)?.argument?.getExpandedType()
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val andExpr1 = true && false
|
||||
const val andExpr2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>nonConstBool && false<!>
|
||||
const val andExpr3 = true && constBool
|
||||
const val andExpr4 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>nonConstBool && constBool<!>
|
||||
|
||||
const val orExpr1 = true || false
|
||||
const val orExpr2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>nonConstBool || false<!>
|
||||
const val orExpr3 = true || constBool
|
||||
const val orExpr4 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>nonConstBool || constBool<!>
|
||||
@@ -0,0 +1,12 @@
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val andExpr1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>true && false<!>
|
||||
const val andExpr2 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConstBool && false<!>
|
||||
const val andExpr3 = true && constBool
|
||||
const val andExpr4 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConstBool && constBool<!>
|
||||
|
||||
const val orExpr1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>true || false<!>
|
||||
const val orExpr2 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConstBool || false<!>
|
||||
const val orExpr3 = true || constBool
|
||||
const val orExpr4 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>nonConstBool || constBool<!>
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// LANGUAGE: +ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val s1 = """ ${ true && false } """
|
||||
const val s2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>""" ${ nonConstBool && false } """<!>
|
||||
const val s3 = """ ${ constBool && false } """
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// LANGUAGE: +ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val s1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>""" ${ true && false } """<!>
|
||||
const val s2 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>""" ${ nonConstBool && false } """<!>
|
||||
const val s3 = """ ${ constBool && false } """
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val s1 = """ ${ true && false } """
|
||||
const val s2 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>""" ${ nonConstBool && false } """<!>
|
||||
const val s3 = """ ${ constBool && false } """
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
|
||||
val nonConstBool = true
|
||||
const val constBool = false
|
||||
|
||||
const val s1 = """ ${ true && false } """
|
||||
const val s2 = <!NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>""" ${ nonConstBool && false } """<!>
|
||||
const val s3 = """ ${ constBool && false } """
|
||||
Generated
+18
@@ -23951,12 +23951,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("binaryLogic.kt")
|
||||
public void testBinaryLogic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/binaryLogic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("compare.kt")
|
||||
public void testCompare() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/compare.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_after.kt")
|
||||
public void testComplexBooleanInStringConcat_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexBooleanInStringConcat_before.kt")
|
||||
public void testComplexBooleanInStringConcat_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/complexBooleanInStringConcat_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constInteraction.kt")
|
||||
public void testConstInteraction() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user