-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Segmentation fault compiling field access of comptime struct at comptime #16468
Comments
From what I can tell neither of those examples are supposed to work:
If you want your example to work as intended by the language, the location that the pointer points to needs to be its own // first example
const Features = struct {
f0: bool = false,
};
var features_storage: Features = .{};
const features: *Features = &features_storage;
export fn useFeature0() void {
features.f0 = true;
}
// second example
const features_alt = struct {
var f0_storage: bool = false;
const f0: *bool = &f0_storage;
};
export fn useFeature0Alt() void {
features_alt.f0.* = true;
} (Note that the pointers are not necessary here; you could remove them and directly assign values to |
The significance of the source code posted above is that it will crash the compiler. |
This found something similar: const S = struct {
fn f(_: @This(), comptime comptime_value: u8) void {
_ = comptime_value;
}
};
fn g(comptime comptime_value: u8) void {
_ = comptime_value;
}
pub fn main() void {
var runtime_value: u8 = 0;
const s = S{};
s.f(runtime_value);
// this errors correctly
// g(runtime_value);
} When running |
Zig Version
0.11.0-dev.4059+17255bed4
Steps to Reproduce and Observed Behavior
Compile example program with
zig build-obj comptime_state_error.zig
comptime_state_error.zig
:Workaround:
Expected Behavior
The text was updated successfully, but these errors were encountered: