Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler crash when indexing an improperly defined enumerated array #4629

Open
chuga-git opened this issue Dec 26, 2024 · 0 comments
Open

Compiler crash when indexing an improperly defined enumerated array #4629

chuga-git opened this issue Dec 26, 2024 · 0 comments

Comments

@chuga-git
Copy link

Context

Odin:    dev-2024-12-nightly:cf53404
OS:      Windows 10 Professional (version: 22H2), build 19045.5247   
CPU:     Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz
RAM:     32440 MiB
Backend: LLVM 18.1.8

Expected Behavior

I expect my confused butchering of the language to not literally butcher the compiler.

Expected warning (see snippet below):

Unhandled enumerated array cases:
	North
	East
	South
	West(checker)

and

Expected a constant enum of type 'Direction' as an array field(checker)

Current Behavior

Improperly defining an enumerated array and then indexing it in the same file will cause an assertion failure before the compiler manages to warn the user of their error.

D:\a\Odin\Odin\src\check_expr.cpp(4946): Assertion Failure: `index_tav.mode == Addressing_Constant`

Odin/src/check_expr.cpp

Lines 4945 to 4947 in ad99d20

TypeAndValue index_tav = fv->field->tav;
GB_ASSERT(index_tav.mode == Addressing_Constant);
ExactValue index_value = index_tav.value;

Steps to Reproduce

Here is a snippet that triggers the failure:

package main

Direction :: enum { North, East, South, West }

// incorrect
DirVecs :: [Direction][2]int {
    North = [2]int{-1, 0},
    East  = [2]int{0, +1},
    South = [2]int{+1, 0},
    West  = [2]int{-1, 0},
}

// correct (for reference)
DirVecs :: [Direction][2]int {
    .North = [2]int{-1, 0},
    .East  = [2]int{0, +1},
    .South = [2]int{+1, 0},
    .West  = [2]int{-1, 0},
}

some_func :: proc(number: int) {
    vec = [2]int{}

    // commenting this out will warn of the mistake above instead of crashing
    if number == 0 {
        vec += DirVecs[.North]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant