diff --git a/src/Sema.zig b/src/Sema.zig index 216200d9d3..81da501d3c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -12262,8 +12262,16 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai break :p null; }; - const runtime_src = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| rs: { - if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val| { + const runtime_src = if (switch (lhs_ty.zigTypeTag()) { + .Array, .Struct => try sema.resolveMaybeUndefVal(lhs), + .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs), + else => unreachable, + }) |lhs_val| rs: { + if (switch (rhs_ty.zigTypeTag()) { + .Array, .Struct => try sema.resolveMaybeUndefVal(rhs), + .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs), + else => unreachable, + }) |rhs_val| { const lhs_sub_val = if (lhs_ty.isSinglePointer()) (try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty)).? else diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 155ac294cf..0faa58a7d4 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -45,6 +45,19 @@ fn getArrayLen(a: []const u32) usize { return a.len; } +test "array concat with undefined" { + { + var array = "hello".* ++ @as([5]u8, undefined); + array[5..10].* = "world".*; + try std.testing.expect(std.mem.eql(u8, &array, "helloworld")); + } + { + var array = @as([5]u8, undefined) ++ "world".*; + array[0..5].* = "hello".*; + try std.testing.expect(std.mem.eql(u8, &array, "helloworld")); + } +} + test "array concat with tuple" { const array: [2]u8 = .{ 1, 2 }; {