K1: report also TYPE_MISMATCH_WARNING in JvmSyntheticAssignmentChecker
#KT-56061 Fixed
This commit is contained in:
committed by
Space Team
parent
f14effa8e8
commit
cab0340497
+18
-4
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+43
-8
@@ -31,6 +31,11 @@ fun foo(container: Container<*>, wrapper: Wrapper<String>) {
|
||||
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>"123"<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>"123"<!>)
|
||||
container.simple = null
|
||||
container.setSimple(null)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>container.simple<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>container.getSimple()<!>)
|
||||
container.simple = null!!
|
||||
}
|
||||
|
||||
fun bar(container: Container<String>, wrapper: Wrapper<String>) {
|
||||
@@ -47,32 +52,62 @@ fun baz(container: Container<Any>, wrapper: Wrapper<String>) {
|
||||
container.setSimple("123")
|
||||
}
|
||||
|
||||
fun gau(container: Container<String>, wrapper: Wrapper<Any>) {
|
||||
fun gau(container: Container<String>, wrapper: Wrapper<Any>, arg: Any) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>456<!>
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>arg<!>
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>O<!>
|
||||
if (arg is String) {
|
||||
container.simple = arg
|
||||
}
|
||||
}
|
||||
|
||||
fun dif(container: Container<String>, wrapper: Wrapper<Int>) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
}
|
||||
|
||||
object O
|
||||
|
||||
fun out(container: Container<out Any>, wrapper: Wrapper<String>) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
container.setWrapper(<!ARGUMENT_TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>"123"<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>"123"<!>)
|
||||
}
|
||||
|
||||
fun inn(container: Container<in String>, wrapper: Wrapper<Any>) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
container.setWrapper(<!ARGUMENT_TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>O<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>456<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>456<!>)
|
||||
}
|
||||
|
||||
val x = 456
|
||||
|
||||
fun inn(container: Container<in String>, wrapper: Wrapper<Any>, arg: Any) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
container.setWrapper(<!ARGUMENT_TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>O<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>456<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>456<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>arg<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>arg<!>)
|
||||
if (arg is String) {
|
||||
container.simple = arg
|
||||
container.setSimple(arg)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> generic(container: Container<out T>, wrapper: Wrapper<out T>, arg: T) {
|
||||
container.wrapper = <!ASSIGNMENT_TYPE_MISMATCH!>wrapper<!>
|
||||
container.setWrapper(<!ARGUMENT_TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>O<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>456<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>456<!>)
|
||||
container.simple = <!ASSIGNMENT_TYPE_MISMATCH!>arg<!>
|
||||
container.setSimple(<!ARGUMENT_TYPE_MISMATCH!>arg<!>)
|
||||
}
|
||||
|
||||
+42
-7
@@ -29,8 +29,13 @@ fun foo(container: Container<*>, wrapper: Wrapper<String>) {
|
||||
<!SYNTHETIC_SETTER_PROJECTED_OUT!>container.wrapper<!> = wrapper
|
||||
container.setWrapper(<!TYPE_MISMATCH!>wrapper<!>)
|
||||
|
||||
container.simple = "123"
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>"123"<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>"123"<!>)
|
||||
container.simple = null
|
||||
container.setSimple(null)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>container.simple<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>container.getSimple()<!>)
|
||||
container<!UNREACHABLE_CODE!>.simple =<!> null!!
|
||||
}
|
||||
|
||||
fun bar(container: Container<String>, wrapper: Wrapper<String>) {
|
||||
@@ -47,32 +52,62 @@ fun baz(container: Container<Any>, wrapper: Wrapper<String>) {
|
||||
container.setSimple("123")
|
||||
}
|
||||
|
||||
fun gau(container: Container<String>, wrapper: Wrapper<Any>) {
|
||||
fun gau(container: Container<String>, wrapper: Wrapper<Any>, arg: Any) {
|
||||
container.wrapper = <!TYPE_MISMATCH!>wrapper<!>
|
||||
container.simple = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>456<!>
|
||||
container.simple = <!TYPE_MISMATCH!>arg<!>
|
||||
container.simple = <!TYPE_MISMATCH!>x<!>
|
||||
container.simple = <!TYPE_MISMATCH!>O<!>
|
||||
if (arg is String) {
|
||||
container.simple = <!DEBUG_INFO_SMARTCAST!>arg<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun dif(container: Container<String>, wrapper: Wrapper<Int>) {
|
||||
container.wrapper = <!TYPE_MISMATCH!>wrapper<!>
|
||||
}
|
||||
|
||||
object O
|
||||
|
||||
fun out(container: Container<out Any>, wrapper: Wrapper<String>) {
|
||||
<!SYNTHETIC_SETTER_PROJECTED_OUT!>container.wrapper<!> = wrapper
|
||||
container.setWrapper(<!TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = "123"
|
||||
container.setSimple(<!TYPE_MISMATCH!>"123"<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>x<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>O<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>456<!>
|
||||
container.setSimple(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>456<!>)
|
||||
}
|
||||
|
||||
fun inn(container: Container<in String>, wrapper: Wrapper<Any>) {
|
||||
val x = 456
|
||||
|
||||
fun inn(container: Container<in String>, wrapper: Wrapper<Any>, arg: Any) {
|
||||
<!SYNTHETIC_SETTER_PROJECTED_OUT!>container.wrapper<!> = wrapper
|
||||
container.setWrapper(<!TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = 456
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>x<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>O<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>456<!>
|
||||
container.setSimple(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>456<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>arg<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>arg<!>)
|
||||
if (arg is String) {
|
||||
container.simple = arg
|
||||
container.setSimple(<!DEBUG_INFO_SMARTCAST!>arg<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> generic(container: Container<out T>, wrapper: Wrapper<out T>, arg: T) {
|
||||
<!SYNTHETIC_SETTER_PROJECTED_OUT!>container.wrapper<!> = wrapper
|
||||
container.setWrapper(<!TYPE_MISMATCH!>wrapper<!>)
|
||||
container.simple = arg
|
||||
container.simple = <!TYPE_MISMATCH!>x<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>x<!>)
|
||||
container.simple = <!TYPE_MISMATCH!>O<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>O<!>)
|
||||
container.simple = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>456<!>
|
||||
container.setSimple(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>456<!>)
|
||||
container.simple = <!TYPE_MISMATCH_WARNING!>arg<!>
|
||||
container.setSimple(<!TYPE_MISMATCH!>arg<!>)
|
||||
}
|
||||
|
||||
+10
-2
@@ -1,12 +1,13 @@
|
||||
package
|
||||
|
||||
public val x: kotlin.Int = 456
|
||||
public fun bar(/*0*/ container: Container<kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.String>): kotlin.Unit
|
||||
public fun baz(/*0*/ container: Container<kotlin.Any>, /*1*/ wrapper: Wrapper<kotlin.String>): kotlin.Unit
|
||||
public fun dif(/*0*/ container: Container<kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.Int>): kotlin.Unit
|
||||
public fun foo(/*0*/ container: Container<*>, /*1*/ wrapper: Wrapper<kotlin.String>): kotlin.Unit
|
||||
public fun gau(/*0*/ container: Container<kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.Any>): kotlin.Unit
|
||||
public fun gau(/*0*/ container: Container<kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.Any>, /*2*/ arg: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T> generic(/*0*/ container: Container<out T>, /*1*/ wrapper: Wrapper<out T>, /*2*/ arg: T): kotlin.Unit
|
||||
public fun inn(/*0*/ container: Container<in kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.Any>): kotlin.Unit
|
||||
public fun inn(/*0*/ container: Container<in kotlin.String>, /*1*/ wrapper: Wrapper<kotlin.Any>, /*2*/ arg: kotlin.Any): kotlin.Unit
|
||||
public fun out(/*0*/ container: Container<out kotlin.Any>, /*1*/ wrapper: Wrapper<kotlin.String>): kotlin.Unit
|
||||
|
||||
public open class Container</*0*/ E : kotlin.Any!> {
|
||||
@@ -21,6 +22,13 @@ public open class Container</*0*/ E : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public object O {
|
||||
private constructor O()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class Wrapper</*0*/ W : kotlin.Any!> {
|
||||
public constructor Wrapper</*0*/ W : kotlin.Any!>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Reference in New Issue
Block a user