Skip to content
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

Assertion `var->value->type == init_value->value.type' failed. with nested struct @typeInfo #1091

Closed
bheads opened this issue Jun 9, 2018 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@bheads
Copy link

bheads commented Jun 9, 2018

Getting an error when trying to read nested struct typeInfo:

zig: /home/bheads/zig/src/codegen.cpp:2813: LLVMOpaqueValue* ir_render_decl_var(CodeGen*, IrExecutable*, IrInstructionDeclVar*): Assertion `var->value->type == init_value->value.type' failed.

     const Network = struct {
         host: []const u8,
         port: u16,
     };
 
     const Foo = struct {
         a: u32,
         network : Network, // remove this and it works
         b: i32,
     };
 
     inline for (@typeInfo(Foo).Struct.fields) |f| {
         const name = f.name;
         const ftype = @typeName(f.field_type);
         warn("field {} {} \n", name, ftype);
    }
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jun 9, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Jun 9, 2018
@ghost
Copy link

ghost commented Jul 22, 2018

I ran into this too, here's my code

const builtin = @import("builtin");

fn find(comptime T: type) ?*T {
  return null;
}

fn generic(comptime SelfType: type) void {
  inline for (@typeInfo(SelfType).Struct.fields) |field| {
    comptime const ComponentType = @typeInfo(field.field_type).Pointer.child;

    // this line seems to be causing the crash
    const maybe_component = find(ComponentType);

    // it works fine if i use this in an expression. only assigning it to a
    // variable fails
    // if (find(ComponentType) != null) {}
  }
}

const A = struct{ unused: u32 };
const B = struct{ unused: u32 };

const Data = struct{
  // works if both fields are the same time!
  one: *A,
  two: *B,
};

test "" {
  generic(Data);
}
zig: /home/dbandstra/zig/src/codegen.cpp:2878: LLVMOpaqueValue* ir_render_decl_var(CodeGen*, IrExecutable*, IrInstructionDeclVar*): Assertion `var->value->type == init_value->value.type' failed.

@ghost
Copy link

ghost commented Jul 22, 2018

probably the same bug? #845 #740 #741 #917

@andrewrk
Copy link
Member

fixed by 09cc1dc

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

2 participants