[FIR] Ignore nullability in the definition of "identity-less"
The definition of a "builtin" already ignores nullability. `Int? === String?` must trigger a diagnostic by design.
This commit is contained in:
committed by
Space Team
parent
5ecedcbb16
commit
8d04ab3142
@@ -15,8 +15,8 @@ fun f(): Unit {
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>A() == 1<!>
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>x === "1"<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>x !== "1"<!>
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>x === "1"<!>
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>x !== "1"<!>
|
||||
|
||||
<!IMPLICIT_BOXING_IN_IDENTITY_EQUALS!>x === 1<!>
|
||||
<!IMPLICIT_BOXING_IN_IDENTITY_EQUALS!>x !== 1<!>
|
||||
|
||||
Vendored
+15
-15
@@ -54,7 +54,7 @@ fun test() {
|
||||
x?.<!NONE_APPLICABLE!>equals<!>(1)
|
||||
|
||||
if (get() == null) {}
|
||||
if (get() === null) {}
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>get() === null<!>) {}
|
||||
|
||||
if (x != null) {
|
||||
x<!UNNECESSARY_SAFE_CALL!>?.<!>hashCode()
|
||||
@@ -113,7 +113,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.hashCode()
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.equals("")
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x<!UNSAFE_CALL!>.<!>toString("")
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x<!UNSAFE_CALL!>.<!>test()
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ fun test() {
|
||||
x?.<!NONE_APPLICABLE!>equals<!>(1)
|
||||
|
||||
if (get() == null) {}
|
||||
if (get() === null) {}
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>get() === null<!>) {}
|
||||
|
||||
if (x == null) {
|
||||
x?.hashCode()
|
||||
@@ -188,19 +188,19 @@ fun test() {
|
||||
x.test2()
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x?.hashCode()
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x?.<!NONE_APPLICABLE!>equals<!>(1)
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x?.test2()
|
||||
}
|
||||
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.test2()
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.equals("")
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.hashCode()
|
||||
}
|
||||
""
|
||||
@@ -266,7 +266,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x.toString()
|
||||
}
|
||||
""
|
||||
@@ -275,7 +275,7 @@ fun test() {
|
||||
emit(1)
|
||||
emit(null)
|
||||
val x = get()
|
||||
if (x === null) {
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>x === null<!>) {
|
||||
x<!UNSAFE_CALL!>.<!>test()
|
||||
}
|
||||
""
|
||||
@@ -300,7 +300,7 @@ fun test() {
|
||||
x?.<!NONE_APPLICABLE!>equals<!>(1)
|
||||
|
||||
if (get() == null) {}
|
||||
if (get() === null) {}
|
||||
if (<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>get() === null<!>) {}
|
||||
|
||||
if (x == null) {
|
||||
x?.hashCode()
|
||||
|
||||
Vendored
+3
-3
@@ -9,7 +9,7 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) {
|
||||
val a2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === f1<!>
|
||||
val a3 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === b1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== b1<!>
|
||||
|
||||
val c1 = fn1 === fn2 || fn1 !== fn2
|
||||
val c1 = <!FORBIDDEN_IDENTITY_EQUALS!>fn1 === fn2<!> || <!FORBIDDEN_IDENTITY_EQUALS!>fn1 !== fn2<!>
|
||||
val c2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== fn1<!>
|
||||
val c3 = <!FORBIDDEN_IDENTITY_EQUALS!>b1 === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>b1 !== fn1<!>
|
||||
|
||||
@@ -17,6 +17,6 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) {
|
||||
|
||||
val d1 = <!FORBIDDEN_IDENTITY_EQUALS!>any === f1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>any !== f1<!>
|
||||
val d2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === any<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== any<!>
|
||||
val d3 = any === fn1 || any !== fn1
|
||||
val d4 = fn1 === any || fn1 !== any
|
||||
val d3 = <!FORBIDDEN_IDENTITY_EQUALS!>any === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>any !== fn1<!>
|
||||
val d4 = <!FORBIDDEN_IDENTITY_EQUALS!>fn1 === any<!> || <!FORBIDDEN_IDENTITY_EQUALS!>fn1 !== any<!>
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) {
|
||||
val a2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === f1<!>
|
||||
val a3 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === b1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== b1<!>
|
||||
|
||||
val c1 = fn1 === fn2 || fn1 !== fn2
|
||||
val c1 = <!FORBIDDEN_IDENTITY_EQUALS!>fn1 === fn2<!> || <!FORBIDDEN_IDENTITY_EQUALS!>fn1 !== fn2<!>
|
||||
val c2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== fn1<!>
|
||||
val c3 = <!FORBIDDEN_IDENTITY_EQUALS!>b1 === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>b1 !== fn1<!>
|
||||
|
||||
@@ -25,6 +25,6 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) {
|
||||
|
||||
val d1 = <!FORBIDDEN_IDENTITY_EQUALS!>any === f1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>any !== f1<!>
|
||||
val d2 = <!FORBIDDEN_IDENTITY_EQUALS!>f1 === any<!> || <!FORBIDDEN_IDENTITY_EQUALS!>f1 !== any<!>
|
||||
val d3 = any === fn1 || any !== fn1
|
||||
val d4 = fn1 === any || fn1 !== any
|
||||
val d3 = <!FORBIDDEN_IDENTITY_EQUALS!>any === fn1<!> || <!FORBIDDEN_IDENTITY_EQUALS!>any !== fn1<!>
|
||||
val d4 = <!FORBIDDEN_IDENTITY_EQUALS!>fn1 === any<!> || <!FORBIDDEN_IDENTITY_EQUALS!>fn1 !== any<!>
|
||||
}
|
||||
|
||||
+4
-4
@@ -75,24 +75,24 @@ fun incompatibleEnumComparisonSmartCast(c: Any?, e: Any?) {
|
||||
|
||||
fun incompatibleIdentityRegardlessNullability(a: Int?, b: String?) {
|
||||
<!EQUALITY_NOT_APPLICABLE!>a == b<!>
|
||||
a === b
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>a === b<!>
|
||||
}
|
||||
|
||||
fun incompatibleIdentityRegardlessNullabilitySmartCast(a: Any?, b: Any?) {
|
||||
if (a is Int? && b is String?) {
|
||||
<!EQUALITY_NOT_APPLICABLE_WARNING!>a == b<!>
|
||||
a === b
|
||||
<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>a === b<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) {
|
||||
c == d
|
||||
c === d
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>c === d<!>
|
||||
}
|
||||
|
||||
fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) {
|
||||
if (c is C? && d is D?) {
|
||||
c == d
|
||||
c === d
|
||||
<!FORBIDDEN_IDENTITY_EQUALS_WARNING!>c === d<!>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user