NI: Report incompatible receiver of callable reference

^KT-35535 Fixed
This commit is contained in:
Denis Zharkov
2019-12-18 15:26:00 +03:00
parent dd56c3d918
commit c486fa6189
8 changed files with 72 additions and 7 deletions
@@ -162,7 +162,7 @@ private fun preprocessCallableReference(
val lhsResult = argument.lhsResult
if (lhsResult is LHSResult.Type) {
csBuilder.addConstraintFromLHS(lhsResult, expectedType)
csBuilder.addConstraintFromLHS(argument, lhsResult, expectedType)
}
val notCallableTypeConstructor =
@@ -181,13 +181,17 @@ private fun preprocessCallableReference(
return result
}
private fun ConstraintSystemBuilder.addConstraintFromLHS(lhsResult: LHSResult.Type, expectedType: UnwrappedType) {
private fun ConstraintSystemBuilder.addConstraintFromLHS(
argument: CallableReferenceKotlinCallArgument,
lhsResult: LHSResult.Type,
expectedType: UnwrappedType
) {
if (!ReflectionTypes.isNumberedTypeWithOneOrMoreNumber(expectedType)) return
val lhsType = lhsResult.unboundDetailedReceiver.stableType
val expectedTypeProjectionForLHS = expectedType.arguments.first()
val expectedTypeForLHS = expectedTypeProjectionForLHS.type
val constraintPosition = LHSArgumentConstraintPosition(lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
val constraintPosition = LHSArgumentConstraintPosition(argument, lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
when (expectedTypeProjectionForLHS.projectionKind) {
Variance.INVARIANT -> addEqualityConstraint(lhsType, expectedTypeForLHS, constraintPosition)
@@ -63,7 +63,10 @@ class KnownTypeParameterConstraintPosition(val typeArgument: KotlinType) : Const
override fun toString() = "TypeArgument $typeArgument"
}
class LHSArgumentConstraintPosition(val receiver: DetailedReceiver) : ConstraintPosition() {
class LHSArgumentConstraintPosition(
val argument: CallableReferenceKotlinCallArgument,
val receiver: DetailedReceiver
) : ConstraintPosition() {
override fun toString(): String {
return "LHS receiver $receiver"
}
@@ -121,4 +124,4 @@ class ConstrainingTypeIsError(
val typeVariable: TypeVariableMarker,
val constraintType: KotlinTypeMarker,
val position: IncorporationConstraintPosition
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)