K1: introduce assignment checkers and convert JvmSyntheticAssignmentChecker
Related to KT-56061
This commit is contained in:
committed by
Space Team
parent
5fc0aa769b
commit
7cc3f7de62
+7
-12
@@ -5,32 +5,27 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.AssignmentChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSynthesized
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.BasicExpressionTypingVisitor
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
|
||||
object JvmSyntheticAssignmentChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
object JvmSyntheticAssignmentChecker : AssignmentChecker {
|
||||
override fun check(assignmentExpression: KtBinaryExpression, context: CallCheckerContext) {
|
||||
val left = assignmentExpression.left ?: return
|
||||
val resolvedCall = left.getResolvedCall(context.trace.bindingContext) ?: return
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (!resultingDescriptor.isSynthesized) return
|
||||
if (resultingDescriptor !is SyntheticJavaPropertyDescriptor) return
|
||||
if (reportOn !is KtNameReferenceExpression) return
|
||||
val binaryExpression = reportOn.getParentOfType<KtBinaryExpression>(strict = true) ?: return
|
||||
if (!BasicExpressionTypingVisitor.isLValue(reportOn, binaryExpression)) return
|
||||
val receiverType = resolvedCall.extensionReceiver?.type ?: return
|
||||
val unsubstitutedReceiverType = resolvedCall.candidateDescriptor.extensionReceiverParameter?.type ?: return
|
||||
if (receiverType.constructor !== unsubstitutedReceiverType.constructor) return
|
||||
@@ -50,6 +45,6 @@ object JvmSyntheticAssignmentChecker : CallChecker {
|
||||
)
|
||||
val substitutedPropertyType = substitutor.substitute(propertyType.unwrap(), Variance.IN_VARIANCE)
|
||||
if (substitutedPropertyType == null || !substitutedPropertyType.isNothing()) return
|
||||
context.trace.report(ErrorsJvm.SYNTHETIC_SETTER_PROJECTED_OUT.on(binaryExpression.left ?: reportOn, resultingDescriptor))
|
||||
context.trace.report(ErrorsJvm.SYNTHETIC_SETTER_PROJECTED_OUT.on(left, resultingDescriptor))
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -63,11 +63,14 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
||||
SamInterfaceConstructorReferenceCallChecker,
|
||||
EnumDeclaringClassDeprecationChecker,
|
||||
UpperBoundViolatedInTypealiasConstructorChecker,
|
||||
JvmSyntheticAssignmentChecker,
|
||||
LateinitIntrinsicApplicabilityChecker(isWarningInPre19 = false),
|
||||
JvmPropertyVsFieldAmbiguityCallChecker,
|
||||
),
|
||||
|
||||
additionalAssignmentCheckers = listOf(
|
||||
JvmSyntheticAssignmentChecker,
|
||||
),
|
||||
|
||||
additionalTypeCheckers = listOf(
|
||||
RuntimeAssertionsTypeChecker,
|
||||
JavaGenericVarianceViolationTypeChecker,
|
||||
|
||||
Reference in New Issue
Block a user