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 failure with @sizeOf() in switch expression #14330

Closed
17dec opened this issue Jan 16, 2023 · 0 comments
Closed

Assertion failure with @sizeOf() in switch expression #14330

17dec opened this issue Jan 16, 2023 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@17dec
Copy link

17dec commented Jan 16, 2023

Zig Version

0.11.0-dev.1280+4b3291764

Steps to Reproduce and Observed Behavior

test "switch sizeof" {
    switch (0) {
        @sizeOf(struct {}) => {},
        else => unreachable,
    }
}

Produces the following error:

thread 27953 panic: reached unreachable code
Analyzing sizeof.zig: sizeof.zig:test.switch sizeof
      %3 = dbg_block_begin()
      %4 = dbg_stmt(2, 5)                                                                                                                                                                      
      %5 = switch_cond(@Zir.Inst.Ref.zero) node_offset:2:13 to :2:14
      %6 = dbg_stmt(2, 13)
      %7 = typeof(%5) node_offset:2:13 to :2:14 
      %9 = extended(struct_decl(anon, Auto, {}, {}, {}) node_offset:3:17 to :3:26
      %10 = size_of(%9) node_offset:3:9 to :3:27
      %11 = as_node(%7, %10) node_offset:3:9 to :3:27
    > %8 = switch_block(%5,
        else => {
          %18 = dbg_block_begin()
          %19 = dbg_stmt(4, 17)
          %20 = unreachable() node_offset:4:17 to :4:28
          %21 = dbg_block_end()
        },
        %11 => {
          %12 = dbg_block_begin()
          %13 = block({
            %14 = restore_err_ret_index(%13, @Zir.Inst.Ref.none)
            %15 = break(%13, @Zir.Inst.Ref.void_value)
          }) node_offset:3:31 to :3:33
          %16 = dbg_block_end()
          %17 = break(%8, @Zir.Inst.Ref.void_value)
        }) node_offset:2:5 to :2:11
      %22 = ensure_result_used(%8) node_offset:2:5 to :2:11
      %23 = dbg_block_end()
      %24 = restore_err_ret_index(%2, @Zir.Inst.Ref.none)
      %25 = break(%2, @Zir.Inst.Ref.void_value)
    For full context, use the command
      zig ast-check -t sizeof.zig

  in sizeof.zig: sizeof.zig:test.switch sizeof
    > %2 = block({%3..%25}) node_offset:1:22 to :1:23

/home/yorhel/src/zig-src/lib/std/debug.zig:281:14: 0x7da946 in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/yorhel/src/zig-src/src/type.zig:2497:63: 0xc4fa72 in hasRuntimeBitsAdvanced (zig)
                    .eager => assert(struct_obj.haveFieldTypes()),

...

Expected Behavior

Successful compilation,

@17dec 17dec added the bug Observed behavior contradicts documented or intended behavior label Jan 16, 2023
@Vexu Vexu added this to the 0.11.0 milestone Jan 16, 2023
Vexu added a commit to Vexu/zig that referenced this issue Jan 16, 2023
Vexu added a commit to Vexu/zig that referenced this issue Jan 16, 2023
Vexu added a commit to Vexu/zig that referenced this issue Jan 16, 2023
Vexu added a commit to Vexu/zig that referenced this issue Jan 16, 2023
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