KTIJ-30581 [kotlin] Optimize isStaticallyImportedReceiver by only considering object receiver types

If the implicit dispatch receiver is not an object, it
is definitely not statically imported, so no point
in performing an expensive `scopeContext` call

GitOrigin-RevId: a408d2a4432d6ed782e10854f0490cd911f1367e
This commit is contained in:
Roman Golyshev
2024-07-30 22:20:28 +00:00
committed by intellij-monorepo-bot
parent f938a230a8
commit cd71a13b09
@@ -173,6 +173,12 @@ internal class UsedReferencesCollector(private val file: KtFile) {
implicitDispatchReceiver: KaImplicitReceiverValue,
containingFile: KtFile
): Boolean {
val receiverTypeSymbol = implicitDispatchReceiver.type.symbol ?: return false
val receiverIsObject = receiverTypeSymbol is KaClassSymbol && receiverTypeSymbol.classKind.isObject
// with static imports, the implicit receiver is either some object symbol or `Unit` in case of imports from Java classes
if (!receiverIsObject) return false
val regularImplicitReceivers = containingFile.scopeContext(element).implicitReceivers
return regularImplicitReceivers.none { it.type.semanticallyEquals(implicitDispatchReceiver.type) }