NI: Report incompatible receiver of callable reference
^KT-35535 Fixed
This commit is contained in:
+7
-3
@@ -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)
|
||||
|
||||
+5
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user