Todd
12/11/2022, 8:38 PMTodd
12/11/2022, 8:38 PMprivate data class Point(
var x: Int,
var y: Int
)
that I am modifying and then inserting into a hashSet. However when I do this I get an error:
kotlin.IllegalStateException: This cannot happen with fixed magic multiplier and grow-only hash array. Have object hashCodes changed?
at kotlin.Throwable#<init>(/opt/buildAgent/work/5f69639f351c4725/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:25)
at kotlin.Exception#<init>(/opt/buildAgent/work/5f69639f351c4725/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
at kotlin.RuntimeException#<init>(/opt/buildAgent/work/5f69639f351c4725/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
at kotlin.IllegalStateException#<init>(/opt/buildAgent/work/5f69639f351c4725/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:70)
at kotlin.collections.HashMap.rehash#internal(/opt/buildAgent/work/5f69639f351c4725/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt:239)
at kotlin.collections.HashMap.ensureCapacity#internal(/opt/buildAgent/work/5f69639f351c4725/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt:193)
at kotlin.collections.HashMap.ensureExtraCapacity#internal(/opt/buildAgent/work/5f69639f351c4725/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt:181)
at kotlin.collections.HashMap#addKey(/opt/buildAgent/work/5f69639f351c4725/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/HashMap.kt:292)
at kotlin.collections.HashSet#add(/opt/buildAgent/work/5f69639f351c4725/kotlin/libraries/stdlib/native-wasm/src/kotlin/collections/HashSet.kt:34)
I tried this on jvm and it seems to work fine. Also just copying the object before putting it in the set fixes the issue as well.Todd
12/11/2022, 8:40 PMTodd
12/11/2022, 8:56 PMephemient
12/11/2022, 10:00 PMephemient
12/11/2022, 10:14 PMNote: Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set.
Todd
12/12/2022, 1:06 AMvsazel
12/14/2022, 8:29 AMcopy()
into new instance.Todd
12/14/2022, 4:42 PM