FIR resolve: check early receivers on kotlin.* only

To provide more stable behaviour, the check introduced in the previous
commit is now applied only to extensions from kotlin.* package.
This commit is contained in:
Mikhail Glukhikh
2019-05-29 19:13:12 +03:00
parent 374b59dee3
commit b7da2f2ad8
2 changed files with 22 additions and 15 deletions
@@ -503,6 +503,10 @@ class ExplicitReceiverTowerDataConsumer<T : ConeSymbol>(
val candidateFactory: CandidateFactory val candidateFactory: CandidateFactory
) : TowerDataConsumer() { ) : TowerDataConsumer() {
companion object {
val defaultPackage = Name.identifier("kotlin")
}
override fun consume( override fun consume(
kind: TowerDataKind, kind: TowerDataKind,
@@ -548,9 +552,11 @@ class ExplicitReceiverTowerDataConsumer<T : ConeSymbol>(
dispatchReceiverValue: ClassDispatchReceiverValue?, dispatchReceiverValue: ClassDispatchReceiverValue?,
implicitExtensionReceiverValue: ImplicitReceiverValue? implicitExtensionReceiverValue: ImplicitReceiverValue?
): ProcessorAction { ): ProcessorAction {
if (symbol is FirFunctionSymbol && symbol.callableId.packageName.startsWith(defaultPackage)) {
val explicitReceiverType = explicitReceiver.type val explicitReceiverType = explicitReceiver.type
if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) { if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) {
val declarationReceiverTypeRef = (symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef val declarationReceiverTypeRef =
(symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef
val declarationReceiverType = declarationReceiverTypeRef?.type val declarationReceiverType = declarationReceiverTypeRef?.type
if (declarationReceiverType is ConeClassType) { if (declarationReceiverType is ConeClassType) {
if (!AbstractTypeChecker.isSubtypeOf( if (!AbstractTypeChecker.isSubtypeOf(
@@ -566,6 +572,7 @@ class ExplicitReceiverTowerDataConsumer<T : ConeSymbol>(
} }
} }
} }
}
val candidate = candidateFactory.createCandidate( val candidate = candidateFactory.createCandidate(
symbol, symbol,
dispatchReceiverValue, dispatchReceiverValue,
@@ -7,7 +7,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
BRANCH BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Array<*> if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.Array<*>
GET_VAR 'x: kotlin.Any declared in <root>.test1' type=kotlin.Any origin=null GET_VAR 'x: kotlin.Any declared in <root>.test1' type=kotlin.Any origin=null
then: ERROR_CALL 'Unresolved reference: <Inapplicable(WRONG_RECEIVER): [kotlin/jvm/isArrayOf]>#' type=IrErrorType then: ERROR_CALL 'Unresolved reference: <Unresolved name: isArrayOf>#' type=IrErrorType
BRANCH BRANCH
if: CONST Boolean type=kotlin.Boolean value=true if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false then: CONST Boolean type=kotlin.Boolean value=false