diff --git a/src/ir.cpp b/src/ir.cpp index 5c09e48b2d..b74a99b37d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16794,7 +16794,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdPromise: case ZigTypeIdVector: { - if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) + ResolveStatus needed_status = (align_bytes == 0) ? + ResolveStatusZeroBitsKnown : ResolveStatusAlignmentKnown; + if ((err = type_resolve(ira->codegen, child_type, needed_status))) return ira->codegen->invalid_instruction; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 707d46fd8c..f477bb64ed 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -27,7 +27,6 @@ comptime { _ = @import("behavior/bugs/2114.zig"); _ = @import("behavior/bugs/2346.zig"); _ = @import("behavior/bugs/2578.zig"); - _ = @import("behavior/bugs/2689.zig"); _ = @import("behavior/bugs/394.zig"); _ = @import("behavior/bugs/421.zig"); _ = @import("behavior/bugs/529.zig"); diff --git a/test/stage1/behavior/bugs/2689.zig b/test/stage1/behavior/bugs/2689.zig deleted file mode 100644 index d1c1062ada..0000000000 --- a/test/stage1/behavior/bugs/2689.zig +++ /dev/null @@ -1,7 +0,0 @@ -test "slice with alignment" { - const S = packed struct { - a: u8, - }; - - var a: []align(8) S = undefined; -} diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index 5fa6c24026..d4a8353ca7 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -54,3 +54,14 @@ test "comptime slices are disambiguated" { expect(sliceSum([_]u8{ 1, 2 }) == 3); expect(sliceSum([_]u8{ 3, 4 }) == 7); } + +test "slice type with custom alignment" { + const LazilyResolvedType = struct { + anything: i32, + }; + var slice: []align(32) LazilyResolvedType = undefined; + var array: [10]LazilyResolvedType align(32) = undefined; + slice = &array; + slice[1].anything = 42; + expect(array[1].anything == 42); +}