diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/TypeHints.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/TypeHints.kt index 21d6154be9f..ee8678f506c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/TypeHints.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/TypeHints.kt @@ -23,18 +23,21 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention +import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.RenderingFormat import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.isError +import org.jetbrains.kotlin.types.typeUtil.containsError +import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes //hack to separate type presentation from param info presentation const val TYPE_INFO_PREFIX = "@TYPE@" private val typeRenderer = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions { textFormat = RenderingFormat.PLAIN + renderUnabbreviatedType = false } fun providePropertyTypeHint(elem: PsiElement): List { @@ -47,8 +50,17 @@ fun providePropertyTypeHint(elem: PsiElement): List { } fun provideTypeHint(element: KtCallableDeclaration, offset: Int): List { - val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(element) - return if (!type.isError && isUnclearType(type, element)) { + var type: KotlinType = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(element).unwrap() + if (type.containsError()) return emptyList() + val name = type.constructor.declarationDescriptor?.name + if (name == SpecialNames.NO_NAME_PROVIDED) { + type = type.immediateSupertypes().singleOrNull() ?: return emptyList() + } + else if (name?.isSpecial == true) { + return emptyList() + } + + return if (isUnclearType(type, element)) { val settings = CodeStyleSettingsManager.getInstance(element.project).currentSettings .getCustomSettings(KotlinCodeStyleSettings::class.java) diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt index de0de556c3f..307244549c0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt @@ -56,4 +56,24 @@ class InlayTypeHintsTest : KotlinLightCodeInsightFixtureTestCase() { HintType.LOCAL_VARIABLE_HINT.option.set(true) check("""fun foo() { for (x: String in listOf("a")) { } }""") } -} \ No newline at end of file + + fun testErrorType() { + HintType.PROPERTY_HINT.option.set(true) + check("""val x = arrayListOf<>()""") + } + + fun testExpandedTypeAlias() { + HintType.PROPERTY_HINT.option.set(true) + check("""val x = arrayListOf(1)""") + } + + fun testAnonymousObject() { + HintType.FUNCTION_HINT.option.set(true) + check("""val o = object : Iterable { + override fun iterator() = object : Iterator { + override fun next() = 1 + override fun hasNext() = true + } + }""") + } +}