mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 17:15:37 +00:00
Sema: allow destructuring vectors
This was intended to work when destructuring was first implemented, and was just unintentionally missed out.
This commit is contained in:
parent
bf0387b6bb
commit
9b394a200a
@ -5205,7 +5205,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
|
||||
const operand_ty = sema.typeOf(operand);
|
||||
|
||||
const can_destructure = switch (operand_ty.zigTypeTag(mod)) {
|
||||
.Array => true,
|
||||
.Array, .Vector => true,
|
||||
.Struct => operand_ty.isTuple(mod),
|
||||
else => false,
|
||||
};
|
||||
|
@ -138,3 +138,14 @@ test "destructure of tuple with comptime fields results in some comptime-known v
|
||||
try expect(b == 42);
|
||||
try expect(d == 42);
|
||||
}
|
||||
|
||||
test "destructure vector" {
|
||||
const vec: @Vector(2, i32) = .{ 1, 2 };
|
||||
const x, const y = vec;
|
||||
|
||||
comptime assert(@TypeOf(x) == i32);
|
||||
comptime assert(@TypeOf(y) == i32);
|
||||
|
||||
try expect(x == 1);
|
||||
try expect(y == 2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user