Skip to content

segfault when trying to append to tuple #3979

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
daurnimator opened this issue Dec 24, 2019 · 2 comments · Fixed by #4570
Closed

segfault when trying to append to tuple #3979

daurnimator opened this issue Dec 24, 2019 · 2 comments · Fixed by #4570
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@daurnimator
Copy link
Contributor

test "" {
    var args = .{};
    args = args ++ .{ "2" };
}
#12 0x0000555555640b3f in ir_assert (ok=false, source_instruction=0x555555dabbb0) at zig/src/ir.cpp:9225
#13 0x0000555555652d18 in ir_analyze_cast (ira=0x555555da9ca0, source_instr=0x555555dabbb0, wanted_type=0x555555daa4b0, value=0x555555dabbb0) at zig/src/ir.cpp:13941
#14 0x00005555556531ef in ir_implicit_cast2 (ira=0x555555da9ca0, value_source_instr=0x555555dabbb0, value=0x555555dabbb0, expected_type=0x555555daa4b0)
    at zig/src/ir.cpp:14003
#15 0x000055555565321e in ir_implicit_cast (ira=0x555555da9ca0, value=0x555555dabbb0, expected_type=0x555555daa4b0) at zig/src/ir.cpp:14007
#16 0x0000555555661689 in ir_analyze_store_ptr (ira=0x555555da9ca0, source_instr=0x555555ba8b30, ptr=0x555555ba6ce0, uncasted_value=0x555555dabbb0, allow_write_through_const=false)
    at zig/src/ir.cpp:17922
#17 0x00005555556893df in ir_analyze_instruction_end_expr (ira=0x555555da9ca0, instruction=0x555555ba8b30) at zig/src/ir.cpp:28115
#18 0x000055555568ad9e in ir_analyze_instruction_base (ira=0x555555da9ca0, instruction=0x555555ba8b30) at zig/src/ir.cpp:28665
#19 0x000055555568b28d in ir_analyze (codegen=0x555555a10b20, old_exec=0x555555ac3420, new_exec=0x555555ac3260, expected_type=0x555555aa96a0, expected_type_source_node=0x0)
    at zig/src/ir.cpp:28750
#20 0x00005555556e02d9 in analyze_fn_ir (g=0x555555a10b20, fn=0x555555ac31e0, return_type_node=0x0) at zig/src/analyze.cpp:4648
#21 0x00005555556e08a6 in analyze_fn_body (g=0x555555a10b20, fn_table_entry=0x555555ac31e0) at zig/src/analyze.cpp:4756
#22 0x00005555556e113f in semantic_analyze (g=0x555555a10b20) at zig/src/analyze.cpp:4868
#23 0x000055555560c2f5 in gen_root_source (g=0x555555a10b20) at zig/src/codegen.cpp:9308
#24 0x0000555555610108 in codegen_build_and_link (g=0x555555a10b20) at zig/src/codegen.cpp:10313
#25 0x00005555555e343d in main (argc=3, argv=0x7fffffffbec8) at zig/src/main.cpp:1351
@daurnimator daurnimator added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Dec 24, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Dec 31, 2019
@jeffkdev
Copy link

jeffkdev commented Feb 9, 2020

Ran into this in 0.5.0+b55bc5e in #4417 . When this is fixed it might be worth testing to make sure the below works as well:

const StructWithDefault = struct {
    value: f32 = 42,
};
const SomeStruct = struct {
    array: [4]StructWithDefault,
};

pub fn main() void {
    // Ok #1: Array element type inferred
    const value0 = SomeStruct{ .array = [_]StructWithDefault{.{}} ++ [_]StructWithDefault{undefined} ** 3 };
    // Ok #2: Array type inferred from defined elements
    const value1 = SomeStruct{ .array = .{ StructWithDefault{}, StructWithDefault{}, StructWithDefault{}, StructWithDefault{} } };
    // Ok #3: Array type and element type inferred
    const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } };
    // error #1: error: expected array, found 'struct:14:4'2 (Define element type, remove array type definition)
    const value3 = SomeStruct{ .array = .{StructWithDefault{}} ++ [_]StructWithDefault{undefined} ** 3 };
    // error #2: error: expected array, found 'struct:16:42' (Remove element type and array type in first arg)
    const value4 = SomeStruct{ .array = .{.{}} ++ [_]StructWithDefault{undefined} ** 3 };
    // error #3: error: expected array, found 'struct:18:52' (Remove element type and array type in both args)
    const value5 = SomeStruct{ .array = .{.{}} ++ .{undefined} ** 3 };
    // error #4: assertion failed. This is a bug in the Zig compiler.
    const value6 = SomeStruct{ .array = .{ .{}, .{}, } ++ .{.{}, .{} }} ;
}

LemonBoy added a commit to LemonBoy/zig that referenced this issue Feb 27, 2020
andrewrk pushed a commit that referenced this issue Feb 27, 2020
@jeffkdev
Copy link

Are the non-compiling cases in the example above (error 1 and 2) tracked in another issue? If not I can reopen the original issue #4417.

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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants