Skip to content

Commit b38226f

Browse files
committed
Use star projections to deal with generic subtypes
1 parent d8a6b79 commit b38226f

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

server/src/main/kotlin/org/javacs/kt/completion/Completions.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
3838
import org.jetbrains.kotlin.types.KotlinType
3939
import org.jetbrains.kotlin.types.TypeUtils
4040
import org.jetbrains.kotlin.types.typeUtil.supertypes
41+
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
4142
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
4243
import java.util.concurrent.TimeUnit
4344

@@ -431,22 +432,14 @@ private fun isParentClass(declaration: DeclarationDescriptor): ClassDescriptor?
431432
else null
432433

433434
private fun isExtensionFor(type: KotlinType, extensionFunction: CallableDescriptor): Boolean {
434-
val receiverType = extensionFunction.extensionReceiverParameter?.type ?: return false
435+
val receiverType = extensionFunction.extensionReceiverParameter?.type?.replaceArgumentsWithStarProjections() ?: return false
435436
return KotlinTypeChecker.DEFAULT.isSubtypeOf(type, receiverType)
436437
|| (TypeUtils.getTypeParameterDescriptorOrNull(receiverType)?.isGenericExtensionFor(type) ?: false)
437-
|| (TypeUtils.getClassDescriptor(receiverType)?.isClassExtensionFor(type) ?: false)
438438
}
439439

440440
private fun TypeParameterDescriptor.isGenericExtensionFor(type: KotlinType): Boolean =
441441
upperBounds.all { KotlinTypeChecker.DEFAULT.isSubtypeOf(type, it) }
442442

443-
// Currently only needed for extensions such as e.g. Collection<T> applied to List<SomeConcreteType>
444-
// Direct subtype relationships will be detected by KotlinTypeChecker.isSubtypeOf
445-
private fun ClassDescriptor.isClassExtensionFor(type: KotlinType): Boolean {
446-
fun matchesFqName(t: KotlinType) = TypeUtils.getClassDescriptor(t)?.fqNameSafe == fqNameSafe
447-
return matchesFqName(type) || type.supertypes().any(::matchesFqName)
448-
}
449-
450443
private val loggedHidden = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build<Pair<Name, Name>, Unit>()
451444

452445
private fun logHidden(target: DeclarationDescriptor, from: DeclarationDescriptor) {

0 commit comments

Comments
 (0)