Odin icon indicating copy to clipboard operation
Odin copied to clipboard

'in' syntax on maps breaks when keys are tagged unions

Open Tetralux opened this issue 2 years ago • 0 comments

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)
}

Tetralux avatar Nov 09 '23 13:11 Tetralux