diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt index 05e6bf52188..db8fefd7a31 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt @@ -224,12 +224,12 @@ private fun KtFunctionLiteral.valueParameterReferences(callExpression: KtCallExp private fun isSingleLine(element: KtCallExpression): Boolean { val qualifiedExpression = element.getQualifiedExpressionForSelector() ?: return true - var receiver = qualifiedExpression.receiverExpression as? KtQualifiedExpression ?: return true + var receiver = qualifiedExpression.receiverExpression if (receiver.lineCount() > 1) return false var count = 1 while (true) { if (count > 2) return false - receiver = receiver.receiverExpression as? KtQualifiedExpression ?: break + receiver = (receiver as? KtQualifiedExpression)?.receiverExpression ?: break count++ } return true diff --git a/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt b/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt new file mode 100644 index 00000000000..ac2120314c4 --- /dev/null +++ b/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +// HIGHLIGHT: INFORMATION + +fun test() { + runCatching { + /* lots of code*/ + }.let { println(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt.after b/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt.after new file mode 100644 index 00000000000..f709f269822 --- /dev/null +++ b/idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +// HIGHLIGHT: INFORMATION + +fun test() { + println(runCatching { + /* lots of code*/ + }) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 5aafa257b22..80570fe22c2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2313,6 +2313,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/complexRedundantLet/longCallChain.kt"); } + @TestMetadata("multipleLines.kt") + public void testMultipleLines() throws Exception { + runTest("idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt"); + } + @TestMetadata("multipleReceiver.kt") public void testMultipleReceiver() throws Exception { runTest("idea/testData/inspectionsLocal/complexRedundantLet/multipleReceiver.kt");