| 1 | const UnionContainer = union { |
| 2 | buf: [2]i32, |
| 3 | }; |
| 4 | |
| 5 | fn getUnionSlice() []i32 { |
| 6 | var c = UnionContainer{ .buf = .{ 1, 2 } }; |
| 7 | return c.buf[0..2]; |
| 8 | } |
| 9 | |
| 10 | const StructContainer = struct { |
| 11 | buf: [2]i32, |
| 12 | }; |
| 13 | |
| 14 | fn getStructSlice() []i32 { |
| 15 | var c = StructContainer{ .buf = .{ 3, 4 } }; |
| 16 | return c.buf[0..2]; |
| 17 | } |
| 18 | |
| 19 | comptime { |
| 20 | @compileLog(getUnionSlice()); |
| 21 | @compileLog(getStructSlice()); |
| 22 | } |
| 23 | |
| 24 | pub fn main() !void {} |
| 25 | |
| 26 | // TODO: the output here has been regressed by #19414. |
| 27 | // Restoring useful output here will require providing a Sema to TypedValue.print. |
| 28 | |
| 29 | // error |
| 30 | // |
| 31 | // :20:5: error: found compile log statement |
| 32 | // |
| 33 | // Compile Log Output: |
| 34 | // @as([]i32, @as([*]i32, @ptrCast(&@as(tmp.UnionContainer, .{ .buf = .{ 1, 2 } }).buf))[0..2]) |
| 35 | // @as([]i32, @as([*]i32, @ptrCast(&@as(tmp.StructContainer, .{ .buf = .{ 3, 4 } }).buf))[0..2]) |