K1: report swallowed diagnostic about receiver type mismatch
#KT-55056 Fixed
This commit is contained in:
committed by
Space Team
parent
176325eaa7
commit
bd27ec840c
+3
-2
@@ -34,10 +34,11 @@ fun resolveKtPrimitive(
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||
receiverInfo: ReceiverInfo,
|
||||
convertedType: UnwrappedType?,
|
||||
inferenceSession: InferenceSession?
|
||||
inferenceSession: InferenceSession?,
|
||||
kotlinCall: KotlinCall? = null,
|
||||
): ResolvedAtom = when (argument) {
|
||||
is SimpleKotlinCallArgument ->
|
||||
checkSimpleArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, convertedType, inferenceSession)
|
||||
checkSimpleArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, convertedType, inferenceSession, kotlinCall)
|
||||
|
||||
is LambdaKotlinCallArgument ->
|
||||
preprocessLambdaArgument(csBuilder, argument, expectedType, diagnosticsHolder)
|
||||
|
||||
+5
-3
@@ -533,7 +533,8 @@ private fun ResolutionCandidate.resolveKotlinArgument(
|
||||
this,
|
||||
receiverInfo,
|
||||
convertedArgument?.unknownIntegerType?.unwrap(),
|
||||
inferenceSession
|
||||
inferenceSession,
|
||||
receiverInfo.selectorCall
|
||||
)
|
||||
|
||||
addResolvedKtPrimitive(resolvedAtom)
|
||||
@@ -647,7 +648,7 @@ private fun ResolutionCandidate.getReceiverArgumentWithConstraintIfCompatible(
|
||||
val expectedTypeUnprepared = argument.getExpectedType(parameter, callComponents.languageVersionSettings)
|
||||
val expectedType = prepareExpectedType(expectedTypeUnprepared)
|
||||
val argumentType = captureFromTypeParameterUpperBoundIfNeeded(argument.receiver.stableType, expectedType)
|
||||
val position = ReceiverConstraintPositionImpl(argument)
|
||||
val position = ReceiverConstraintPositionImpl(argument, resolvedCall.atom)
|
||||
return if (csBuilder.isSubtypeConstraintCompatible(argumentType, expectedType, position))
|
||||
ApplicableContextReceiverArgumentWithConstraint(argument, argumentType, expectedType, position)
|
||||
else null
|
||||
@@ -732,7 +733,8 @@ internal object CheckReceivers : ResolutionPart() {
|
||||
val receiverInfo = ReceiverInfo(
|
||||
isReceiver = true,
|
||||
shouldReportUnsafeCall = implicitInvokeState != ImplicitInvokeCheckStatus.UNSAFE_INVOKE_REPORTED,
|
||||
reportUnsafeCallAsUnsafeImplicitInvoke = implicitInvokeState == ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE
|
||||
reportUnsafeCallAsUnsafeImplicitInvoke = implicitInvokeState == ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE,
|
||||
selectorCall = resolvedCall.atom
|
||||
)
|
||||
|
||||
resolveKotlinArgument(receiverArgument, receiverParameter, receiverInfo)
|
||||
|
||||
+17
-7
@@ -35,6 +35,7 @@ class ReceiverInfo(
|
||||
val isReceiver: Boolean,
|
||||
val shouldReportUnsafeCall: Boolean, // should not report if unsafe implicit invoke has been reported already
|
||||
val reportUnsafeCallAsUnsafeImplicitInvoke: Boolean,
|
||||
val selectorCall: KotlinCall? = null,
|
||||
) {
|
||||
init {
|
||||
assert(!reportUnsafeCallAsUnsafeImplicitInvoke || shouldReportUnsafeCall) { "Inconsistent receiver info" }
|
||||
@@ -52,11 +53,15 @@ fun checkSimpleArgument(
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||
receiverInfo: ReceiverInfo,
|
||||
convertedType: UnwrappedType?,
|
||||
inferenceSession: InferenceSession?
|
||||
inferenceSession: InferenceSession?,
|
||||
kotlinCall: KotlinCall?
|
||||
): ResolvedAtom = when (argument) {
|
||||
is ExpressionKotlinCallArgument -> checkExpressionArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo.isReceiver, convertedType)
|
||||
is SubKotlinCallArgument -> checkSubCallArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, inferenceSession)
|
||||
else -> unexpectedArgument(argument)
|
||||
is ExpressionKotlinCallArgument ->
|
||||
checkExpressionArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo.isReceiver, convertedType, kotlinCall)
|
||||
is SubKotlinCallArgument ->
|
||||
checkSubCallArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, inferenceSession)
|
||||
else ->
|
||||
unexpectedArgument(argument)
|
||||
}
|
||||
|
||||
private fun checkExpressionArgument(
|
||||
@@ -65,7 +70,8 @@ private fun checkExpressionArgument(
|
||||
expectedType: UnwrappedType?,
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||
isReceiver: Boolean,
|
||||
convertedType: UnwrappedType?
|
||||
convertedType: UnwrappedType?,
|
||||
kotlinCall: KotlinCall?
|
||||
): ResolvedAtom {
|
||||
val resolvedExpression = ResolvedExpressionAtom(expressionArgument)
|
||||
if (expectedType == null) return resolvedExpression
|
||||
@@ -93,7 +99,9 @@ private fun checkExpressionArgument(
|
||||
return null
|
||||
}
|
||||
|
||||
val position = if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument) else ArgumentConstraintPositionImpl(expressionArgument)
|
||||
val position =
|
||||
if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument, kotlinCall)
|
||||
else ArgumentConstraintPositionImpl(expressionArgument)
|
||||
|
||||
// Used only for arguments with @NotNull annotation
|
||||
if (expectedType is NotNullTypeParameter && argumentType.isMarkedNullable) {
|
||||
@@ -188,7 +196,9 @@ private fun checkSubCallArgument(
|
||||
if (expectedType == null) return subCallResult
|
||||
|
||||
val expectedNullableType = expectedType.makeNullableAsSpecified(true)
|
||||
val position = if (receiverInfo.isReceiver) ReceiverConstraintPositionImpl(subCallArgument) else ArgumentConstraintPositionImpl(subCallArgument)
|
||||
val position =
|
||||
if (receiverInfo.isReceiver) ReceiverConstraintPositionImpl(subCallArgument, subCallArgument.callResult.resultCallAtom.atom)
|
||||
else ArgumentConstraintPositionImpl(subCallArgument)
|
||||
|
||||
// subArgument cannot has stable smartcast
|
||||
// return type can contains fixed type variables
|
||||
|
||||
+4
-1
@@ -39,7 +39,10 @@ class ArgumentConstraintPositionImpl(argument: KotlinCallArgument) : ArgumentCon
|
||||
class CallableReferenceConstraintPositionImpl(val callableReferenceCall: CallableReferenceKotlinCall) :
|
||||
CallableReferenceConstraintPosition<CallableReferenceResolutionAtom>(callableReferenceCall)
|
||||
|
||||
class ReceiverConstraintPositionImpl(argument: KotlinCallArgument) : ReceiverConstraintPosition<KotlinCallArgument>(argument)
|
||||
class ReceiverConstraintPositionImpl(
|
||||
argument: KotlinCallArgument,
|
||||
val kotlinCall: KotlinCall?
|
||||
) : ReceiverConstraintPosition<KotlinCallArgument>(argument)
|
||||
|
||||
class FixVariableConstraintPositionImpl(
|
||||
variable: TypeVariableMarker,
|
||||
|
||||
Reference in New Issue
Block a user