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,21 +552,24 @@ class ExplicitReceiverTowerDataConsumer<T : ConeSymbol>(
dispatchReceiverValue: ClassDispatchReceiverValue?, dispatchReceiverValue: ClassDispatchReceiverValue?,
implicitExtensionReceiverValue: ImplicitReceiverValue? implicitExtensionReceiverValue: ImplicitReceiverValue?
): ProcessorAction { ): ProcessorAction {
val explicitReceiverType = explicitReceiver.type if (symbol is FirFunctionSymbol && symbol.callableId.packageName.startsWith(defaultPackage)) {
if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) { val explicitReceiverType = explicitReceiver.type
val declarationReceiverTypeRef = (symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef if (dispatchReceiverValue == null && explicitReceiverType is ConeClassType) {
val declarationReceiverType = declarationReceiverTypeRef?.type val declarationReceiverTypeRef =
if (declarationReceiverType is ConeClassType) { (symbol as? FirCallableSymbol)?.fir?.receiverTypeRef as? FirResolvedTypeRef
if (!AbstractTypeChecker.isSubtypeOf( val declarationReceiverType = declarationReceiverTypeRef?.type
candidateFactory.inferenceComponents.ctx, if (declarationReceiverType is ConeClassType) {
explicitReceiverType, if (!AbstractTypeChecker.isSubtypeOf(
declarationReceiverType.lookupTag.constructClassType( candidateFactory.inferenceComponents.ctx,
declarationReceiverType.typeArguments.map { ConeStarProjection }.toTypedArray(), explicitReceiverType,
isNullable = true 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 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