diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index ec7f4257b3c..92e084ccf35 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java @@ -467,8 +467,11 @@ public class KtPsiUtil { } if (parentElement instanceof KtCallExpression && currentInner == ((KtCallExpression) parentElement).getCalleeExpression()) { + KtCallExpression parentCall = (KtCallExpression) parentElement; if (innerExpression instanceof KtSimpleNameExpression) return false; if (KtPsiUtilKt.getQualifiedExpressionForSelector(parentElement) != null) return true; + if (innerExpression instanceof KtCallExpression + && parentCall.getValueArgumentList() == null) return true; return !(innerExpression instanceof KtThisExpression || innerExpression instanceof KtArrayAccessExpression || innerExpression instanceof KtConstantExpression diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/callInsideCallWithLambdaOnly.kt b/idea/testData/intentions/removeUnnecessaryParentheses/callInsideCallWithLambdaOnly.kt new file mode 100644 index 00000000000..f0bebe72fb7 --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/callInsideCallWithLambdaOnly.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun parenPB(p: (() -> Unit) -> Unit): (() -> Unit) -> Unit = p + +fun somethingNext(p: (() -> Unit) -> Unit) { + (parenPB (p)) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/copy/copyFunCallQualificationWithParentheses/after/bar/some2.kt b/idea/testData/refactoring/copy/copyFunCallQualificationWithParentheses/after/bar/some2.kt index 35c16cb247e..7583faf3633 100644 --- a/idea/testData/refactoring/copy/copyFunCallQualificationWithParentheses/after/bar/some2.kt +++ b/idea/testData/refactoring/copy/copyFunCallQualificationWithParentheses/after/bar/some2.kt @@ -11,5 +11,5 @@ fun some2(p1: () -> Unit, p2: (() -> Unit) -> Unit) { parenP() parenBP { p1 }() parenPP()() - parenPB(p2) {} + (parenPB(p2)) {} } \ 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 28449e32978..5912b9408ef 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -13439,6 +13439,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeUnnecessaryParentheses"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("callInsideCallWithLambdaOnly.kt") + public void testCallInsideCallWithLambdaOnly() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/callInsideCallWithLambdaOnly.kt"); + doTest(fileName); + } + @TestMetadata("necessaryParentheses1.kt") public void testNecessaryParentheses1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeUnnecessaryParentheses/necessaryParentheses1.kt");