From 96cddb6b7b0caa5a1d3dbd8db54aefde1a6f2d84 Mon Sep 17 00:00:00 2001 From: mglukhikh Date: Mon, 23 Jan 2017 19:23:56 +0300 Subject: [PATCH] False positive in "Remove redundant let" fixed #KT-15884 Fixed --- .../idea/intentions/ReplaceSingleLineLetIntention.kt | 3 ++- .../replaceSingleLineLetIntention/binarySafeCall.kt | 5 +++++ .../dotWithComparison.kt | 6 ++++++ .../idea/intentions/IntentionTestGenerated.java | 12 ++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/replaceSingleLineLetIntention/binarySafeCall.kt create mode 100644 idea/testData/intentions/replaceSingleLineLetIntention/dotWithComparison.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt index 7cad0320a47..2cc3a9abb52 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSingleLineLetIntention.kt @@ -116,7 +116,8 @@ class ReplaceSingleLineLetIntention : SelfTargetingOffsetIndependentIntention return true + is KtConstantExpression -> return true + else -> return false } } diff --git a/idea/testData/intentions/replaceSingleLineLetIntention/binarySafeCall.kt b/idea/testData/intentions/replaceSingleLineLetIntention/binarySafeCall.kt new file mode 100644 index 00000000000..c32e59956cb --- /dev/null +++ b/idea/testData/intentions/replaceSingleLineLetIntention/binarySafeCall.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +val x = 1 +val y = x.let { it + it?.hashCode() } \ No newline at end of file diff --git a/idea/testData/intentions/replaceSingleLineLetIntention/dotWithComparison.kt b/idea/testData/intentions/replaceSingleLineLetIntention/dotWithComparison.kt new file mode 100644 index 00000000000..99457243ed6 --- /dev/null +++ b/idea/testData/intentions/replaceSingleLineLetIntention/dotWithComparison.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +fun main(args: Array) { + args[0].let { it.isBlank() && it.toByteOrNull() != null } +} \ 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 5e2edddfbf2..a959aa31e2b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12633,12 +12633,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("binarySafeCall.kt") + public void testBinarySafeCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/binarySafeCall.kt"); + doTest(fileName); + } + @TestMetadata("comparisons.kt") public void testComparisons() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/comparisons.kt"); doTest(fileName); } + @TestMetadata("dotWithComparison.kt") + public void testDotWithComparison() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/dotWithComparison.kt"); + doTest(fileName); + } + @TestMetadata("lambdaWithBinaryExpression.kt") public void testLambdaWithBinaryExpression() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/lambdaWithBinaryExpression.kt");