From bf7f7c81b16ce9c399cacf3caa33569e4664ea11 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sat, 2 Feb 2019 10:51:30 +0900 Subject: [PATCH] Redundant explict type: do not report for aliased types #KT-29128 Fixed --- .../idea/inspections/RedundantExplicitTypeInspection.kt | 2 ++ .../inspectionsLocal/redundantExplicitType/typealias.kt | 7 +++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 idea/testData/inspectionsLocal/redundantExplicitType/typealias.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantExplicitTypeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantExplicitTypeInspection.kt index c1e5f2581ba..641ad09e463 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantExplicitTypeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantExplicitTypeInspection.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeIntention import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.types.AbbreviatedType class RedundantExplicitTypeInspection : AbstractKotlinInspection() { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = @@ -22,6 +23,7 @@ class RedundantExplicitTypeInspection : AbstractKotlinInspection() { val initializer = property.initializer ?: return val type = property.resolveToDescriptorIfAny()?.type ?: return + if (type is AbbreviatedType) return when (initializer) { is KtConstantExpression -> { when (initializer.node.elementType) { diff --git a/idea/testData/inspectionsLocal/redundantExplicitType/typealias.kt b/idea/testData/inspectionsLocal/redundantExplicitType/typealias.kt new file mode 100644 index 00000000000..2f056a00b0f --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantExplicitType/typealias.kt @@ -0,0 +1,7 @@ +// PROBLEM: none + +fun main() { + val id: Id = 11 +} + +typealias Id = Int \ 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 87259ca957b..1aa13b2a769 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -4882,6 +4882,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testTop() throws Exception { runTest("idea/testData/inspectionsLocal/redundantExplicitType/top.kt"); } + + @TestMetadata("typealias.kt") + public void testTypealias() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantExplicitType/typealias.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/redundantGetter")