From 581f83421ad228b8789af83055c54be6396af33f Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Mon, 27 Jan 2020 18:16:25 +0900 Subject: [PATCH] Unnecessary parentheses in function call with lambda: don't report for function named 'suspend' #KT-22878 Fixed --- .../RemoveEmptyParenthesesFromLambdaCallIntention.kt | 1 + .../removeEmptyParenthesesFromLambdaCall/suspend.kt | 6 ++++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 5 +++++ 3 files changed, 12 insertions(+) create mode 100644 idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/suspend.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt index beb51dfae92..a3f72272b44 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt @@ -31,6 +31,7 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio override fun applicabilityRange(element: KtValueArgumentList): TextRange? { if (element.arguments.isNotEmpty()) return null val parent = element.parent as? KtCallExpression ?: return null + if (parent.calleeExpression?.text == "suspend") return null val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: return null if (element.getLineNumber(start = false) != singleLambdaArgument.getLineNumber(start = true)) return null val prev = element.getPrevSiblingIgnoringWhitespaceAndComments() diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/suspend.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/suspend.kt new file mode 100644 index 00000000000..76b344998c1 --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/suspend.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +fun suspend(body: () -> Int) {} + +fun main() { + val wInvokeCall = suspend() { 42 } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 12809045e19..7f7c08e3dff 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -13520,6 +13520,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { public void testSimple() throws Exception { runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/simple.kt"); } + + @TestMetadata("suspend.kt") + public void testSuspend() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/suspend.kt"); + } } @TestMetadata("idea/testData/intentions/removeEmptyPrimaryConstructor")