[kotlin] KTIJ-36447 Handle binary expression

GitOrigin-RevId: c2d54a40db1b8ad500845a18d750c3ab52a4b6ce
This commit is contained in:
Vladimir Dolzhenko
2025-11-15 22:48:52 +00:00
committed by intellij-monorepo-bot
parent 3986ae8da0
commit fd218e6170
5 changed files with 34 additions and 1 deletions
@@ -38,7 +38,7 @@ internal object NoReturnValueFactory {
val newExpression = buildNewExpression(factory, element, parent)
val elementToReplace = when (parent) {
is KtParenthesizedExpression -> parent
is KtParenthesizedExpression, is KtBinaryExpression -> parent
else -> element
}.let(updater::getWritable)
@@ -58,6 +58,9 @@ internal object NoReturnValueFactory {
is KtParenthesizedExpression if parent.parent !is KtContainerNode -> {
factory.createDeclaration("val _ = ${parent.text}")
}
is KtBinaryExpression -> {
factory.createDeclaration("val _ = ${parent.text}")
}
is KtParenthesizedExpression, is KtWhenEntry, is KtContainerNode -> {
factory.createExpression("{$baseExpressionText}")
}
@@ -8019,6 +8019,11 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("binaryExpressions.kt")
public void testBinaryExpressions() throws Exception {
runTest("../../../idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt");
}
@TestMetadata("if.kt")
public void testIf() throws Exception {
runTest("../../../idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/if.kt");
@@ -9772,6 +9772,11 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("binaryExpressions.kt")
public void testBinaryExpressions() throws Exception {
runTest("testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt");
}
@TestMetadata("if.kt")
public void testIf() throws Exception {
runTest("testData/quickfix/explicitlyIgnoreReturnValue/if.kt");
@@ -0,0 +1,10 @@
// "Explicitly ignore return value" "true"
// LANGUAGE_VERSION: 2.2
// COMPILER_ARGUMENTS: -Xreturn-value-checker=full
fun someFunction() {
<caret>someFunctionValue() ?: error("failure")
}
fun someFunctionValue(): Int? = 1
// IGNORE_K1
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix
@@ -0,0 +1,10 @@
// "Explicitly ignore return value" "true"
// LANGUAGE_VERSION: 2.2
// COMPILER_ARGUMENTS: -Xreturn-value-checker=full
fun someFunction() {
<caret>val _ = someFunctionValue() ?: error("failure")
}
fun someFunctionValue(): Int? = 1
// IGNORE_K1
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix