Odin
Odin copied to clipboard
Procedures with constant params fail to initialize struct with where clause
Setup
Odin: dev-2024-10:af9ae4897
OS: Debian GNU/Linux 12 (bookworm), Linux 5.15.146.1-microsoft-standard-WSL2
CPU: AMD Ryzen 7 5800X 8-Core Processor
RAM: 15956 MiB
Backend: LLVM 14.0.6
Odin: dev-2024-04-nightly:aab122ede
OS: Windows 11 Home Basic (version: 23H2), build 22631.4317
CPU: AMD Ryzen 7 5800X 8-Core Processor
RAM: 32691 MiB
Backend: LLVM 17.0.1
Expected Behavior
Given the following code:
Foo :: struct($N: int) where N >= 0 {
to_init: int,
elems: [N]int,
}
new_foo :: proc($N : int) -> (foo: Foo(N)) {
foo.to_init = 1
return
}
main :: proc() {
SIZE :: 1000
f := new_foo(SIZE)
}
Is expected that the variable foo will be successfully initialized by the procedure new_foo since the constant SIZE is greater than 0 (thus respecting the where clause) and the size of the underlying array is passed through the constant procedure parameter $N.
Current Behavior
While trying to compile, the initialization of the variable foo cause the compiler to fail. This has been discovered while trying to wrap a Small_Array in a struct carrying extra information.
Failure Information (for bugs)
Trying to initialize the wrapper of a Small_Array, the compiler gives the following logs:
~/odin-lang/Odin/core/container/small_array/small_array.odin(7:16) Error: at caller location
Small_Array :: struct($N: int, $T: typeid) where N >= 0 { ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
~/odin-lang/Odin/core/container/small_array/small_array.odin(7:50) Error: 'where' clauses expect a constant boolean evaluation
Small_Array :: struct($N: int, $T: typeid) where N >= 0 {
^~~~~^
Wrapping an array in a struct with a where clause of where N >= 0, the compiler gives the following logs:
~/main.odin(13:8) Error: at caller location
Foo :: struct($N : int) where N >= 0 { ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
~/main.odin(13:31) Error: 'where' clauses expect a constant boolean evaluation
Foo :: struct($N : int) where N >= 0 {
^~~~~^