-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Comptime Struct Field Assignment #6656
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
Labels
bug
Observed behavior contradicts documented or intended behavior
miscompilation
The compiler reports success but produces semantically incorrect code.
stage1
The process of building from source via WebAssembly and the C backend.
Milestone
Comments
This idea is covered by #5895 ! |
Expected behavior is a compile error when you try to set |
Closed
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 7, 2022
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 7, 2022
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 8, 2022
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 9, 2022
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
kcbanner
pushed a commit
to kcbanner/zig
that referenced
this issue
Dec 10, 2022
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
TUSF
pushed a commit
to TUSF/zig
that referenced
this issue
May 9, 2024
Closes ziglang#2622 Closes ziglang#2727 Closes ziglang#6047 Closes ziglang#6947 Closes ziglang#6656
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Observed behavior contradicts documented or intended behavior
miscompilation
The compiler reports success but produces semantically incorrect code.
stage1
The process of building from source via WebAssembly and the C backend.
I ran into a strange situation with struct fields that are declared comptime. It appears that they must be assigned an initial value in their declaration (which makes sense), but then assigning them explicitly does not change this value.
The code below is accepted and runs, but the value set in the initialization of the struct (in the init function) is not used. This causes the final testing.expect to fail because the value of 'id' is still true.
This may be the expect behavior for comptime fields, but it seems that the 'init' function shouldn't compile in this case.
The purpose of this code was an attempt to perform compile-time checking of state transitions. Type parameters work, but only allow a single output state (perhaps a minor limitation). Without the ability to be generic over the output type (as far as I can tell) the only way I could think to write a function that might return different states was comptime assertions on a comptime field which held the current state.
The text was updated successfully, but these errors were encountered: