odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.12k stars 550 forks source link

Fix `bit_set` construction crash on constant non-integer field #3772

Closed Feoramund closed 2 weeks ago

Feoramund commented 2 weeks ago

Found this when I switched a struct to be a bit_set. The following program fails an assertion:

package main

main :: proc() {
    E :: enum {
        Alpha,
        Beta,
    }

    BS :: bit_set[E]

    f := BS{ true }
}
oskarnp commented 2 weeks ago

I don't think this is supposed to compile.

Kelimion commented 2 weeks ago

I don't think this is supposed to compile.

I don't think so either, but neither should it assert. An error message that you can't use bool in an int bit set would be appropriate here.

Feoramund commented 2 weeks ago

I don't think this is supposed to compile.

The PR does not make it compile.

An error message that you can't use bool in an int bit set would be appropriate here.

/tmp/odin/crash/crash.odin(11:11) Error: Cannot convert untyped value 'true' to 'E' from 'untyped bool'
f := BS{ true }
^~~^

Something more specific than what is already being displayed?

oskarnp commented 2 weeks ago

I don't think this is supposed to compile.

The PR does not make it compile.

My bad! Sorry.

An error message that you can't use bool in an int bit set would be appropriate here.

/tmp/odin/crash/crash.odin(11:11) Error: Cannot convert untyped value 'true' to 'E' from 'untyped bool'
  f := BS{ true }
           ^~~^

Something more specific than what is already being displayed?

This seems fine then.

Kelimion commented 2 weeks ago

I don't think this is supposed to compile.

The PR does not make it compile.

An error message that you can't use bool in an int bit set would be appropriate here.

/tmp/odin/crash/crash.odin(11:11) Error: Cannot convert untyped value 'true' to 'E' from 'untyped bool'
  f := BS{ true }
           ^~~^

Something more specific than what is already being displayed?

No, this is great. Thanks.