Odin
Odin copied to clipboard
Compiler segfault with declaration cycle in enum
Context
With latest Odin
Odin: dev-2022-12:521ed286
OS: Manjaro Linux, Linux 5.10.151-1-MANJARO
CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
and this invalid program:
package main
import "core:fmt"
E :: enum {
A = 0,
B = 1,
C = E.A | E.B,
}
main :: proc() {
fmt.println(E.C)
}
Expected Behavior
An error, or acceptance with C = 0|1
Current Behavior
bug.odin(5:1) Illegal declaration cycle of `E`
Segmentation fault (core dumped)
I believe you need to refer to the enum value like C = A | B
package main
Flags :: bit_set[Flags; u8]
main :: proc() {
fl: Flags
}
This code results in the same error and segmentation fault (Linux and Windows) Odin: dev-2023-10 OS: Windows 10 Unknown Edition (00000064) (version: 22H2), build 19045.3570 CPU: Intel(R) Core(TM) i3-7100U CPU @ 2.40GHz RAM: 16253 MiB
The bug is a bug, but I'll post a workaround for the original problem, just in case anyone stumbles upon it. You can re-use existing enum values like this:
E :: enum {
A = 0,
B = 1,
C = A | B,
}
I'm pretty sure the same issue appears if you use implicit secectors (e.g. .A) too