From b8ae13b3d92aa102d4a0cb38bdf5f01833fb4033 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Mon, 2 Mar 2020 16:13:03 +0900 Subject: [PATCH] RedundantLetInspection: remove 'let' safe call correctly #KT-37148 Fixed --- .../kotlin/idea/inspections/RedundantLetInspection.kt | 2 +- .../inspectionsLocal/simpleRedundantLet/reference5.kt | 2 ++ .../inspectionsLocal/simpleRedundantLet/reference5.kt.after | 2 ++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt create mode 100644 idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt index 6d908a4fb4b..a75bfd23557 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantLetInspection.kt @@ -146,7 +146,7 @@ private fun KtDotQualifiedExpression.applyTo(element: KtCallExpression) { } private fun deleteCall(element: KtCallExpression) { - val parent = element.parent as? KtDotQualifiedExpression + val parent = element.parent as? KtQualifiedExpression if (parent != null) { val replacement = parent.selectorExpression?.takeIf { it != element } ?: parent.receiverExpression parent.replace(replacement) diff --git a/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt b/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt new file mode 100644 index 00000000000..00df3e08d6a --- /dev/null +++ b/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val a = 1?.let { it }?.let { it } \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt.after b/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt.after new file mode 100644 index 00000000000..665d9d07c08 --- /dev/null +++ b/idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt.after @@ -0,0 +1,2 @@ +// WITH_RUNTIME +val a = 1?.let { it } \ 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 36ae57319dd..1ab6ecd9e7c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -12450,6 +12450,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/simpleRedundantLet/reference4.kt"); } + @TestMetadata("reference5.kt") + public void testReference5() throws Exception { + runTest("idea/testData/inspectionsLocal/simpleRedundantLet/reference5.kt"); + } + @TestMetadata("sameLets.kt") public void testSameLets() throws Exception { runTest("idea/testData/inspectionsLocal/simpleRedundantLet/sameLets.kt");