-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Closed
Copy link
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone
Description
Zig Version
0.10.0-dev.2882+556f12174
Steps to Reproduce
This fails as expected:
test {
const T = struct {
comptime x: i32 = 0,
comptime y: u8 = 123,
};
var a: T = .{.x = -1234, .y = 0};
_ = a;
}However, both of these currently compile when they should not:
pub const U = struct {
comptime foo: u32 = 1,
bar: u32,
};
fn foo(x: U) void {
_ = x;
}
test {
_ = foo(U{ .foo = 2, .bar = 2 });
}test {
var x: u32 = 15;
const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
var a: T = .{ -1234, 5678, x + 1 };
_ = a;
}Expected Behavior
All three tests above should fail with the error message "value stored in comptime field does not match the default value of the field"
Actual Behavior
The second test compiles successfully. The third test panics due to generating a runtime store to a comptime field.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.