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
) : TowerDataConsumer() {
companion object {
val defaultPackage = Name.identifier("kotlin")
}
override fun consume(
kind: TowerDataKind,
@@ -548,21 +552,24 @@ class ExplicitReceiverTowerDataConsumer<T : ConeSymbol>(
dispatchReceiverValue: ClassDispatchReceiverValue?,
implicitExtensionReceiverValue: ImplicitReceiverValue?
): ProcessorAction {
val explicitReceiverType = explicitReceiver.type
if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) {
val declarationReceiverTypeRef = (symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef
val declarationReceiverType = declarationReceiverTypeRef?.type
if (declarationReceiverType is ConeClassType) {
if (!AbstractTypeChecker.isSubtypeOf(
candidateFactory.inferenceComponents.ctx,
explicitReceiverType,
declarationReceiverType.lookupTag.constructClassType(
declarationReceiverType.typeArguments.map { ConeStarProjection }.toTypedArray(),
isNullable = true
if (symbol is FirFunctionSymbol && symbol.callableId.packageName.startsWith(defaultPackage)) {
val explicitReceiverType = explicitReceiver.type
if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) {
val declarationReceiverTypeRef =
(symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef
val declarationReceiverType = declarationReceiverTypeRef?.type
if (declarationReceiverType is ConeClassType) {
if (!AbstractTypeChecker.isSubtypeOf(
candidateFactory.inferenceComponents.ctx,
explicitReceiverType,
declarationReceiverType.lookupTag.constructClassType(
declarationReceiverType.typeArguments.map { ConeStarProjection }.toTypedArray(),
isNullable = true
)
)
)
) {
return ProcessorAction.NEXT
) {
return ProcessorAction.NEXT
}
}
}
}
@@ -7,7 +7,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
BRANCH
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
then: ERROR_CALL 'Unresolved reference: <Inapplicable(WRONG_RECEIVER): [kotlin/jvm/isArrayOf]>#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: <Unresolved name: isArrayOf>#' type=IrErrorType
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false