You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PersistentMap.equals sometimes returns false even though all map entries are equal!
This is quite serious as comparing PersistentMap is a basic functionality.
We have seen this in the wild. Below is a fully self-contained test to reproduce it. The problem seems to be related with the node structure and the 'minus' / remove method.
Affected versions: at least 0.3.5 and 0.3.8
importkotlinx.collections.immutable.minusimportkotlinx.collections.immutable.persistentMapOfimportnet.oddpoet.expect.extension.equalimportnet.oddpoet.expect.shouldimportkotlin.test.TestclassPersistentMapEqualsBugTest {
privateclassChosenHashCode(
privatevalhashCode:Int,
privatevalname:String,
) {
overridefunequals(other:Any?): Boolean {
return other isChosenHashCode&& (other.name == name)
}
overridefunhashCode(): Int {
return hashCode
}
overridefuntoString(): String {
return name
}
}
@Test
fun`debug PersistentMap equals`() {
val a =ChosenHashCode(123, "A")
val b =ChosenHashCode(123, "B")
val c =ChosenHashCode(123, "C")
val abc = persistentMapOf(
a to "x",
b to "y",
c to "z",
)
val minusAb = abc.minus(arrayOf(a, b))
val cOnly = persistentMapOf(c to "z")
minusAb.entries.should.equal(cOnly.entries) // passes
minusAb.should.equal(cOnly) // fails
}
}
The text was updated successfully, but these errors were encountered:
PersistentMap.equals
sometimes returns false even though all map entries are equal!This is quite serious as comparing PersistentMap is a basic functionality.
We have seen this in the wild. Below is a fully self-contained test to reproduce it. The problem seems to be related with the node structure and the 'minus' /
remove
method.Affected versions: at least 0.3.5 and 0.3.8
The text was updated successfully, but these errors were encountered: