K1: report also TYPE_MISMATCH_WARNING in JvmSyntheticAssignmentChecker

#KT-56061 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-01-25 17:56:13 +01:00
committed by Space Team
parent f14effa8e8
commit cab0340497
4 changed files with 113 additions and 21 deletions
@@ -6,11 +6,14 @@
package org.jetbrains.kotlin.resolve.jvm.checkers
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.resolve.calls.checkers.AssignmentChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.checkers.isAssignmentCorrectWithDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tower.isSynthesized
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.util.getType
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
@@ -20,6 +23,9 @@ import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typeUtil.isNothing
object JvmSyntheticAssignmentChecker : AssignmentChecker {
private val TYPE_MISMATCH_ERRORS = setOf(Errors.TYPE_MISMATCH, Errors.CONSTANT_EXPECTED_TYPE_MISMATCH, Errors.NULL_FOR_NONNULL_TYPE)
override fun check(assignmentExpression: KtBinaryExpression, context: CallCheckerContext) {
val left = assignmentExpression.left ?: return
val resolvedCall = left.getResolvedCall(context.trace.bindingContext) ?: return
@@ -43,8 +49,16 @@ object JvmSyntheticAssignmentChecker : AssignmentChecker {
substitutionParameters.toTypedArray(), substitutionArguments.toTypedArray(), approximateContravariantCapturedTypes = true
)
)
val substitutedPropertyType = substitutor.substitute(propertyType.unwrap(), Variance.IN_VARIANCE)
if (substitutedPropertyType == null || !substitutedPropertyType.isNothing()) return
context.trace.report(ErrorsJvm.SYNTHETIC_SETTER_PROJECTED_OUT.on(left, resultingDescriptor))
val substitutedPropertyType = substitutor.substitute(propertyType.unwrap(), Variance.IN_VARIANCE) ?: return
if (substitutedPropertyType.isNothing()) {
context.trace.report(ErrorsJvm.SYNTHETIC_SETTER_PROJECTED_OUT.on(left, resultingDescriptor))
return
}
val rValue = assignmentExpression.right ?: return
val rValueType = rValue.getType(context.trace.bindingContext) ?: return
if (isAssignmentCorrectWithDataFlowInfo(substitutedPropertyType, rValue, rValueType, context)) return
if (context.trace.bindingContext.diagnostics.forElement(rValue).none { it.factory in TYPE_MISMATCH_ERRORS }) {
context.trace.report(Errors.TYPE_MISMATCH_WARNING.on(rValue, substitutedPropertyType, rValueType))
}
}
}
}