Odin
Odin copied to clipboard
'in' syntax on maps breaks when keys are tagged unions
package main
import "core:fmt"
main :: proc() {
Key :: union {
string,
int,
}
m: map[Key]f64
for i in 0..<10 {
m[i] = f64(i)
m[fmt.tprint(i)] = f64(i * 2)
}
for i in 0..<10 {
// These asserts fail without the cast to Key.
// But this failure can also seemingly manifest as a segfault in the default_hasher code,
// which is what seemed to happen in my real code.
assert(Key(i) in m)
assert(Key(fmt.tprint(i)) in m)
}
fmt.println(m)
}