-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
OutStream in struct gives runtime unreachable in debug and release-safe #1633
Comments
This is related to #591. Basically, what you're doing is copying a field you should never copy.
The |
This should fix your code (haven't tested): const io = @import("std").io;
pub const Mandelbrot = struct {
out: @typeOf((io.getStdOut() catch unreachable).outStream()),
pub fn init(m: *Mandelbrot) void{
m.out = (io.getStdOut() catch unreachable).outStream();
}
};
pub fn main() void {
var doesntMatter : usize = 1234;
var mb : Mandelbrot = undefined;
Mandelbrot.init(&mb);
// comment this variable and the runtime crash won't happen
var doesMatter : usize = 42;
_ = mb.out.stream.print("{}\n",@intCast(usize,123)); // crash
} |
Thank you, it seems this is a known zig issue. It's funny how optimizations suppress the crash. |
The following code compiles but crashes on runtime.
The crash happens only if the variable
doesMatter
is there and only ifdebug
or--release-safe
is used.By the way, it does not compile on 0.3, only on Master, see https://godbolt.org/z/0yVCLg .
Is my code flawed or is this a zig bug ?
The crash output is
Thank you in advance.
The text was updated successfully, but these errors were encountered: