Redundant explict type: do not report for aliased types
#KT-29128 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
25952036af
commit
bf7f7c81b1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeIntention
|
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeIntention
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.types.AbbreviatedType
|
||||||
|
|
||||||
class RedundantExplicitTypeInspection : AbstractKotlinInspection() {
|
class RedundantExplicitTypeInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
||||||
@@ -22,6 +23,7 @@ class RedundantExplicitTypeInspection : AbstractKotlinInspection() {
|
|||||||
val initializer = property.initializer ?: return
|
val initializer = property.initializer ?: return
|
||||||
|
|
||||||
val type = property.resolveToDescriptorIfAny()?.type ?: return
|
val type = property.resolveToDescriptorIfAny()?.type ?: return
|
||||||
|
if (type is AbbreviatedType) return
|
||||||
when (initializer) {
|
when (initializer) {
|
||||||
is KtConstantExpression -> {
|
is KtConstantExpression -> {
|
||||||
when (initializer.node.elementType) {
|
when (initializer.node.elementType) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val id: Id<caret> = 11
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias Id = Int
|
||||||
+5
@@ -4882,6 +4882,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
public void testTop() throws Exception {
|
public void testTop() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/redundantExplicitType/top.kt");
|
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")
|
@TestMetadata("idea/testData/inspectionsLocal/redundantGetter")
|
||||||
|
|||||||
Reference in New Issue
Block a user