Skip to content

Commit 2f03112

Browse files
committed
handle destrcture declaration unused vars
1 parent 680b3f4 commit 2f03112

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

server/src/main/kotlin/org/javacs/kt/inlayhints/InlayHint.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
3030
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
3131
import org.jetbrains.kotlin.resolve.calls.smartcasts.getKotlinTypeForComparison
3232
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
33+
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
3334
import org.jetbrains.kotlin.types.KotlinType
3435
import org.jetbrains.kotlin.types.error.ErrorType
3536

@@ -50,8 +51,14 @@ private fun PsiElement.determineType(ctx: BindingContext): KotlinType? =
5051
} else null
5152
}
5253
is KtDestructuringDeclarationEntry -> {
53-
val resolvedCall = ctx[BindingContext.COMPONENT_RESOLVED_CALL, this]
54-
resolvedCall?.resultingDescriptor?.returnType
54+
//skip unused variable denoted by underscore
55+
//https://kotlinlang.org/docs/destructuring-declarations.html#underscore-for-unused-variables
56+
if (this.isSingleUnderscore) {
57+
null
58+
} else {
59+
val resolvedCall = ctx[BindingContext.COMPONENT_RESOLVED_CALL, this]
60+
resolvedCall?.resultingDescriptor?.returnType
61+
}
5562
}
5663
is KtProperty -> {
5764
val type = this.getKotlinTypeForComparison(ctx)

0 commit comments

Comments
 (0)