Don't show type hint for local variable initialized with object

#KT-17964 Fixed
This commit is contained in:
Dmitry Jemerov
2017-12-19 12:57:42 +01:00
parent 77c186442a
commit cf6b71aa05
2 changed files with 14 additions and 0 deletions
@@ -54,6 +54,11 @@ fun provideTypeHint(element: KtCallableDeclaration, offset: Int): List<InlayInfo
if (type.containsError()) return emptyList()
val name = type.constructor.declarationDescriptor?.name
if (name == SpecialNames.NO_NAME_PROVIDED) {
if (element is KtProperty && element.isLocal) {
// for local variables, an anonymous object type is not collapsed to its supertype,
// so showing the supertype will be misleading
return emptyList()
}
type = type.immediateSupertypes().singleOrNull() ?: return emptyList()
}
else if (name?.isSpecial == true) {
@@ -96,4 +96,13 @@ class InlayTypeHintsTest : KotlinLightCodeInsightFixtureTestCase() {
}
}""")
}
fun testAnonymousObjectNoBaseType() {
HintType.LOCAL_VARIABLE_HINT.option.set(true)
check("""fun foo() {
val o = object {
val x: Int = 0
}
}""")
}
}