odin-lang / odin-lang.org

http://odin-lang.org
22 stars 81 forks source link

Overview example for switch statement that uses arch := ODIN_ARCH produces multiple compilation errors #143

Closed mahSource closed 12 months ago

mahSource commented 12 months ago

The block causing errors is under the header: https://odin-lang.org/docs/overview/#switch-statement

    switch arch := ODIN_ARCH; arch {  // (1) error for using switch and not #partial switch
    case .i386, .wasm32:
        fmt.println("32 bit")
    case .amd64, .wasm64, .arm64:  //    (2) error for incluing .wasm64
        fmt.println("64 bit")
    case .Unknown:
        fmt.println("Unknown architecture")
    }

(1) Suggested Corrections: Need to add .arm32, remove .wasm64, and add .wasm64p32 then it will work. o/w get error that need #partial switch, as well as undeclared name since .wasm64 was replaced with .wasm64p32 and it is missing .arm32.

(2) Suggested code update -- this works with no errors or warnings:

    switch arch := ODIN_ARCH; arch {
    case .i386, .wasm32, .arm32:
        fmt.println("32 bit")
    case .amd64, .wasm64p32, .arm64:
        fmt.println("64 bit")
    case .Unknown:
        fmt.println("Unknown architecture")
    }
mahSource commented 12 months ago

Thank you!

mahSource commented 12 months ago

I think we removed the main function by mistake. Original code line 388 Need to likely add this back in so it will compile.

main :: proc() {
Kelimion commented 12 months ago

I think we removed the main function by mistake. Original code line 388 Need to likely add this back in so it will compile.

main :: proc() {

Good catch. But I'll just remove the top lines instead. The rest of the switch examples are also just about the switch, not its wider integration into a procedure.