Don't show type hint for local variable initialized with object
#KT-17964 Fixed
This commit is contained in:
@@ -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
|
||||
}
|
||||
}""")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user