Surprising new behaviour of Maybe initialization

As I unfortunately can’t register on Github (they’re harassing me for a phone number and then never sending the SMS verification…), I’ll make a bug report here.

Basically, this assertion fails:

assert(Maybe(int){} == nil) // this used to be true, but now the it's equal to 0!

x0: Maybe(int)
x1 := Maybe(int){}
fmt.println(x0, x1) // prints nil 0, whereas I'd expect it to print nil nil

I suppose this is possibly related to #5671?

2 Likes

Coming from C++, am I just misunderstanding what {} means? Any input, anyone?

x1: union{int} = {}
fmt.println(x1 == nil) // true, as expected

x2 := union{int}{}
fmt.println(x2 == nil) // False. WTF?

odin report:

Odin: dev-2025-10:2508b8287
OS: Manjaro Linux, Linux 6.16.8-1-MANJARO
CPU: Intel(R) Core™ i7-3610QM CPU @ 2.30GHz
RAM: 7820 MiB
Backend: LLVM 20.1.8

I believe this has been fixed now on the next release.

3 Likes

I see, thank you, so I wasn’t going crazy. I believe you mean this was fixed in #5831, but in fact it wasn’t fixed or a separate bug.

package bug

main :: proc() {
  // This part was fixed in #5831
  {
    a: Maybe(int) = {}
    b: Maybe(int) = nil
    assert(a == b)
  }

  x1: union{int} = {}
  assert(x1 == nil)

  x2 := union{int}{}
  assert(x2 == nil) // This still fails
}

1 Like

This has now been fixed.

2 Likes