[FE 1.0] Properly report NON_TRIVIAL_BOOLEAN_CONSTANT on parenthesized expressions

^KT-39883
This commit is contained in:
Dmitriy Novozhilov
2021-10-20 16:40:47 +03:00
committed by teamcityserver
parent 1513e739c6
commit f52361ac2b
2 changed files with 7 additions and 4 deletions
@@ -422,7 +422,10 @@ private class ConstantExpressionEvaluatorVisitor(
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitSimplificationOfNonTrivialConstBooleanExpressions)) {
return true
} else {
val parent = expression.parent
var parent = expression.parent
while (parent is KtParenthesizedExpression) {
parent = parent.parent
}
if (
parent is KtWhenConditionWithExpression ||
parent is KtContainerNode && (parent.parent is KtWhileExpression || parent.parent is KtDoWhileExpression)
@@ -9,8 +9,8 @@ fun test_0(b: Boolean): String = when (b) {
// Deprecated
fun test_1(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!> (b) {
1 == 1 -> "true"
"" != "" -> "false"
(1 == 1) -> "true"
("" != "") -> "false"
}
const val TRUE = true
@@ -27,5 +27,5 @@ const val s2 = "s2"
// Already not working
fun test_3(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
true -> "true"
s1 == s2 -> "false"
(s1 == s2) -> "false"
}