-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Zig Version
0.11.0-dev.3031+f40539e5d
Steps to Reproduce and Observed Behavior
pub fn main() void {
var e: error{Foo} = error.Foo;
const p: *error{ Foo, Bar } = &e;
p.* = error.Bar;
@import("std").log.info("{}", .{e});
}Output:
info: error.Bar
This output should be impossible, since e is of type error{Foo} so should not be able to hold the value error.Bar.
Expected Behavior
A compile error should be triggered.
This happens because a pointer *T is allowed to coerce to a pointer *U whenever T is in-memory coercible to U. When the target pointer is not const, this is insufficient: it is also a requirement that U be in-memory coercible to T, so that writes to the pointer cannot assign invalid values to the destination.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior