odin-lang / Odin

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

Compiler segfault with declaration cycle in enum #2233

Open jrfondren opened 1 year ago

jrfondren commented 1 year ago

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)
Lperlind commented 1 year ago

I believe you need to refer to the enum value like C = A | B

avanspector commented 8 months ago
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

flysand7 commented 8 months ago

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