| ... | @@ -12,6 +12,55 @@ test "decl literal" { | ... | @@ -12,6 +12,55 @@ test "decl literal" { |
| 12 | try expect(val.x == 123); | 12 | try expect(val.x == 123); |
| 13 | } | 13 | } |
| 14 | | 14 | |
| | 15 | test "decl literal with optional" { |
| | 16 | const S = struct { |
| | 17 | x: u32, |
| | 18 | const foo: ?@This() = .{ .x = 123 }; |
| | 19 | }; |
| | 20 | |
| | 21 | const val: ?S = .foo; |
| | 22 | try expect(val.?.x == 123); |
| | 23 | } |
| | 24 | |
| | 25 | test "decl literal with pointer" { |
| | 26 | const S = struct { |
| | 27 | x: u32, |
| | 28 | const foo: *const @This() = &.{ .x = 123 }; |
| | 29 | }; |
| | 30 | |
| | 31 | const val: *const S = .foo; |
| | 32 | try expect(val.x == 123); |
| | 33 | } |
| | 34 | |
| | 35 | test "call decl literal with optional" { |
| | 36 | if (builtin.zig_backend == .stage2_riscv64 or |
| | 37 | builtin.zig_backend == .stage2_sparc64 or |
| | 38 | builtin.zig_backend == .stage2_arm or |
| | 39 | builtin.zig_backend == .stage2_aarch64 or |
| | 40 | builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO |
| | 41 | const S = struct { |
| | 42 | x: u32, |
| | 43 | fn init() ?@This() { |
| | 44 | return .{ .x = 123 }; |
| | 45 | } |
| | 46 | }; |
| | 47 | |
| | 48 | const val: ?S = .init(); |
| | 49 | try expect(val.?.x == 123); |
| | 50 | } |
| | 51 | |
| | 52 | test "call decl literal with pointer" { |
| | 53 | const S = struct { |
| | 54 | x: u32, |
| | 55 | fn init() *const @This() { |
| | 56 | return &.{ .x = 123 }; |
| | 57 | } |
| | 58 | }; |
| | 59 | |
| | 60 | const val: *const S = .init(); |
| | 61 | try expect(val.x == 123); |
| | 62 | } |
| | 63 | |
| 15 | test "call decl literal" { | 64 | test "call decl literal" { |
| 16 | const S = struct { | 65 | const S = struct { |
| 17 | x: u32, | 66 | x: u32, |