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

Self reference though fn ptr field segfaults compiler #1208

Hejsil opened this Issue Jul 7, 2018 · 1 comment


None yet
2 participants

Hejsil commented Jul 7, 2018

const A = struct {
    f: fn(A) u8,

test "" {
    var a: A = undefined;
4448 segmentation fault (core dumped)  zig test test.zig

This comment has been minimized.


andrewrk commented Sep 25, 2018

In the process of fixing a different bug I added this assert and comment, which this bug is now tripping:

        // If this assertion trips, look up the call stack. Probably something is
        // calling type_resolve with ResolveStatusAlignmentKnown when it should only
        // be resolving ResolveStatusZeroBitsKnown
        assert(field->type_entry != nullptr);

I looked up the stack, and sure enough, that was the fix. Thanks, self!

--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1184,7 +1184,7 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
             gen_param_info->src_index = i;
             gen_param_info->gen_index = SIZE_MAX;
-            if ((err = ensure_complete_type(g, type_entry)))
+            if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
                 return g->builtin_types.entry_invalid;
             if (is_c_abi)

@andrewrk andrewrk closed this in eafb8e8 Sep 25, 2018

emekoi added a commit to emekoi/zig that referenced this issue Sep 27, 2018

emekoi added a commit to emekoi/zig that referenced this issue Sep 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment