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

Procedures with constant params fail to initialize struct with where clause #4380

Open
dr4ghs opened this issue Oct 15, 2024 · 0 comments
Open

Comments

@dr4ghs
Copy link

dr4ghs commented Oct 15, 2024

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 { 
                                      ^~~~~^ 
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