diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/NoReturnValueFactory.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/NoReturnValueFactory.kt index 0bdced203042..a69ebdbf7037 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/NoReturnValueFactory.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/NoReturnValueFactory.kt @@ -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}") } diff --git a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java index 7e69376d1ee0..323fbaee2e6a 100644 --- a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java +++ b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java @@ -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"); diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java index 65cfb723ffe4..4de5c125165d 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java @@ -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"); diff --git a/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt b/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt new file mode 100644 index 000000000000..d3a519ceb03e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt @@ -0,0 +1,10 @@ +// "Explicitly ignore return value" "true" +// LANGUAGE_VERSION: 2.2 +// COMPILER_ARGUMENTS: -Xreturn-value-checker=full +fun someFunction() { + someFunctionValue() ?: error("failure") +} +fun someFunctionValue(): Int? = 1 + +// IGNORE_K1 +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt.after new file mode 100644 index 000000000000..3a1ddaef59c9 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/binaryExpressions.kt.after @@ -0,0 +1,10 @@ +// "Explicitly ignore return value" "true" +// LANGUAGE_VERSION: 2.2 +// COMPILER_ARGUMENTS: -Xreturn-value-checker=full +fun someFunction() { + val _ = someFunctionValue() ?: error("failure") +} +fun someFunctionValue(): Int? = 1 + +// IGNORE_K1 +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix \ No newline at end of file