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

stage2: Panic when initializing Tuple with explicit type #11182

Closed
topolarity opened this issue Mar 15, 2022 · 0 comments · Fixed by #11749
Closed

stage2: Panic when initializing Tuple with explicit type #11182

topolarity opened this issue Mar 15, 2022 · 0 comments · Fixed by #11749
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@topolarity
Copy link
Contributor

Zig Version

0.10.0-dev.1335+c64279b15

Steps to Reproduce

test {
    const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
    var a = T{ 0, 0 };
    _ = a;
}

Expected Behavior

Test should pass.

Test is a minor variant of #11159, but the root cause is quite different. In this case, AstGen and the AIR expect to be able to refer to the "elem_type" of the initialized array.

Tuples are initialized like arrays but their fields are heterogeneous like structs, so this fails in Sema.

Actual Behavior

Test crashes:

thread 16327 panic: reached unreachable code
Analyzing testme.zig: testme.zig:test_0
      %2 = dbg_stmt(2, 5)
      %3 = typeof_builtin({
        %4 = as_node(@Ref.i32_type, @Ref.zero) node_offset:2:35
        %5 = as_node(@Ref.u32_type, @Ref.zero) node_offset:2:48
        %6 = array_init_anon(.{%4, %5}) node_offset:2:24
        %7 = break_inline(%3, %6)
      }) node_offset:2:15
      %8 = dbg_var_val(%3, "T")
      %9 = dbg_stmt(3, 5)
      %10 = alloc_inferred_mut() node_offset:3:5
      %11 = validate_array_init_ty(%3) node_offset:3:14
    > %12 = elem_type(%3) node_offset:3:13
      %13 = coerce_result_ptr(%3, %10)
      %14 = elem_ptr_imm(%13, 0) node_offset:3:16
      %15 = store_node(%14, @Ref.zero) node_offset:3:16
      %16 = elem_ptr_imm(%13, 1) node_offset:3:19
      %17 = store_node(%16, @Ref.zero) node_offset:3:19
      %18 = validate_array_init({
        %14 = elem_ptr_imm(%13, 0) node_offset:3:16
        %16 = elem_ptr_imm(%13, 1) node_offset:3:19
      }) node_offset:3:14
      %19 = resolve_inferred_alloc(%10) node_offset:3:5
      %20 = dbg_var_ptr(%10, "a")
      %21 = dbg_stmt(4, 5)
      %22 = load(%10) node_offset:4:9
      %23 = ensure_result_non_error(%22) node_offset:4:9
      %24 = ret_tok(@Ref.void_value) token_offset:5:1
    For full context, use the command
      zig ast-check -t testme.zig


/home/topolarity/repos/zig/src/type.zig:3374:21: 0x2c85805 in type.Type.childType (zig)
            else => unreachable,
                    ^
/home/topolarity/repos/zig/src/Sema.zig:5204:42: 0x331096b in Sema.zirElemType (zig)
    const elem_type = array_type.elemType();
                                         ^
/home/topolarity/repos/zig/src/Sema.zig:671:66: 0x31cc82c in Sema.analyzeBodyInner (zig)
            .elem_type                    => try sema.zirElemType(block, inst),
                                                                 ^
/home/topolarity/repos/zig/src/Sema.zig:541:30: 0x31c035a in Sema.analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
    ```
@topolarity topolarity added the bug Observed behavior contradicts documented or intended behavior label Mar 15, 2022
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Mar 15, 2022
@Vexu Vexu added this to the 0.10.0 milestone Mar 27, 2022
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants