Skip to content

Compiler assert when trying to unwrap return type type #1011

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

Closed
0joshuaolson1 opened this issue May 14, 2018 · 3 comments
Closed

Compiler assert when trying to unwrap return type type #1011

0joshuaolson1 opened this issue May 14, 2018 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@0joshuaolson1
Copy link

0joshuaolson1 commented May 14, 2018

No std.debug.warn for me:

const io = @import("std").io;

fn getPrint() type {
  return struct {
    const f = try io.getStdOut();                // there's an error here if we remove "catch unreachable" in main
//    const f = io.getStdOut() catch unreachable; // also 'works', moving the error to the next line instead
    const stdout = &io.FileOutStream.init(&f).stream;
    pub fn rint(s: []const u8) void {
      stdout.print(s) catch unreachable;
    }
  };
}
pub fn main() void {
  const p = getPrint() catch unreachable; // segfault
//  p.rint("s"); // desired payload of this closure hack (no per-call "catch unreachable" boilerplate)
}

zig version 0.2.0.a6ae4514

P.S. I couldn't figure out the argument signature for passing stdout to a function that handles the "catch unreachable" boilerplate - using OutStream(error{...}) doesn't match the "anonymous error union" with the expected type... (#764)

@andrewrk andrewrk added this to the 0.3.0 milestone May 14, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label May 14, 2018
@andrewrk
Copy link
Member

getStdOut happens to work at comptime on Linux, but it does not work at comptime on Windows - it has to call GetStdHandle.

@0joshuaolson1
Copy link
Author

0joshuaolson1 commented May 14, 2018

I compiled this on Linux, btw.

@Hejsil
Copy link
Contributor

Hejsil commented May 30, 2018

Here is a smaller example:

fn getU8() type {
    return u8;
}
test "" {
    const u = getU8() catch unreachable;
}
zig: zig/src/ir.cpp:17918: TypeTableEntry* ir_analyze_instruction_unwrap_err_payload(IrAnalyze*, IrInstructionUnwrapErrPayload*): Assertion `ptr_type->id == TypeTableEntryIdPointer' failed.

@Hejsil Hejsil changed the title Compiler segfaults when "catch unreachable" prevents compiler errors in struct global declaration Compiler assert when trying to unwrap return type type May 30, 2018
@Hejsil Hejsil closed this as completed in 15302e8 May 30, 2018
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
Projects
None yet
Development

No branches or pull requests

3 participants