| author | |
| committer | |
| log | 9b394a200a55c8347e32607dcff568e8482ada48 |
| tree | 5dcce4e6c5620e1dcabff2d2daa20e7ea7e42751 |
| parent | bf0387b6bb9c65c30f14e699a2f2cfbfea27184e |
This was intended to work when destructuring was first implemented, and
was just unintentionally missed out.2 files changed, 12 insertions(+), 1 deletions(-)
src/Sema.zig+1-1| ... | @@ -5205,7 +5205,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -5205,7 +5205,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5205 | const operand_ty = sema.typeOf(operand); | 5205 | const operand_ty = sema.typeOf(operand); |
| 5206 | 5206 | ||
| 5207 | const can_destructure = switch (operand_ty.zigTypeTag(mod)) { | 5207 | const can_destructure = switch (operand_ty.zigTypeTag(mod)) { |
| 5208 | .Array => true, | 5208 | .Array, .Vector => true, |
| 5209 | .Struct => operand_ty.isTuple(mod), | 5209 | .Struct => operand_ty.isTuple(mod), |
| 5210 | else => false, | 5210 | else => false, |
| 5211 | }; | 5211 | }; |
test/behavior/destructure.zig+11| ... | @@ -138,3 +138,14 @@ test "destructure of tuple with comptime fields results in some comptime-known v | ... | @@ -138,3 +138,14 @@ test "destructure of tuple with comptime fields results in some comptime-known v |
| 138 | try expect(b == 42); | 138 | try expect(b == 42); |
| 139 | try expect(d == 42); | 139 | try expect(d == 42); |
| 140 | } | 140 | } |
| 141 | |||
| 142 | test "destructure vector" { | ||
| 143 | const vec: @Vector(2, i32) = .{ 1, 2 }; | ||
| 144 | const x, const y = vec; | ||
| 145 | |||
| 146 | comptime assert(@TypeOf(x) == i32); | ||
| 147 | comptime assert(@TypeOf(y) == i32); | ||
| 148 | |||
| 149 | try expect(x == 1); | ||
| 150 | try expect(y == 2); | ||
| 151 | } |