[FIR] Report == for identity-less
Since we forbid overriding `equals` for value classes, and value classes may only implement interfaces, we know everything about their `equals`, hence we can guarantee if it always returns `false` for different value classes.
This commit is contained in:
committed by
Space Team
parent
8d04ab3142
commit
c9d7b47900
+2
-1
@@ -80,6 +80,7 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() {
|
|||||||
|
|
||||||
private fun checkEqualityApplicability(l: TypeInfo, r: TypeInfo, context: CheckerContext): Applicability {
|
private fun checkEqualityApplicability(l: TypeInfo, r: TypeInfo, context: CheckerContext): Applicability {
|
||||||
val oneIsBuiltin = l.isBuiltin || r.isBuiltin
|
val oneIsBuiltin = l.isBuiltin || r.isBuiltin
|
||||||
|
val oneIsIdentityLess = l.isIdentityLess || r.isIdentityLess
|
||||||
|
|
||||||
// The compiler should only check comparisons
|
// The compiler should only check comparisons
|
||||||
// when builtins are involved.
|
// when builtins are involved.
|
||||||
@@ -87,7 +88,7 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() {
|
|||||||
// the list of special fqNames described in RULES1
|
// the list of special fqNames described in RULES1
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
oneIsBuiltin && shouldReportAsPerRules1(l, r, context) -> getInapplicabilityFor(l, r)
|
(oneIsBuiltin || oneIsIdentityLess) && shouldReportAsPerRules1(l, r, context) -> getInapplicabilityFor(l, r)
|
||||||
else -> Applicability.APPLICABLE
|
else -> Applicability.APPLICABLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -86,13 +86,13 @@ fun incompatibleIdentityRegardlessNullabilitySmartCast(a: Any?, b: Any?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) {
|
fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) {
|
||||||
c == d
|
<!EQUALITY_NOT_APPLICABLE!>c == d<!>
|
||||||
<!FORBIDDEN_IDENTITY_EQUALS!>c === d<!>
|
<!FORBIDDEN_IDENTITY_EQUALS!>c === d<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) {
|
fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) {
|
||||||
if (c is C? && d is D?) {
|
if (c is C? && d is D?) {
|
||||||
c == d
|
<!EQUALITY_NOT_APPLICABLE_WARNING!>c == d<!>
|
||||||
<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>c === d<!>
|
<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>c === d<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user