| ... | ... | @@ -436,6 +436,10 @@ const Parser = struct { |
| 436 | 436 | T: type, |
| 437 | 437 | node: Zoir.Node.Index, |
| 438 | 438 | ) error{ ParseZon, OutOfMemory, WrongType }!T { |
| 439 | if (T == Zoir.Node.Index) { |
| 440 | return node; |
| 441 | } |
| 442 | |
| 439 | 443 | switch (@typeInfo(T)) { |
| 440 | 444 | .optional => |optional| if (node.get(self.zoir) == .null) { |
| 441 | 445 | return null; |
| ... | ... | @@ -3441,3 +3445,27 @@ test "std.zon add pointers" { |
| 3441 | 3445 | try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{}", .{status}); |
| 3442 | 3446 | } |
| 3443 | 3447 | } |
| 3448 | |
| 3449 | test "std.zon stop on node" { |
| 3450 | const gpa = std.testing.allocator; |
| 3451 | |
| 3452 | { |
| 3453 | const Vec2 = struct { |
| 3454 | x: Zoir.Node.Index, |
| 3455 | y: f32, |
| 3456 | }; |
| 3457 | |
| 3458 | var status: Status = .{}; |
| 3459 | defer status.deinit(gpa); |
| 3460 | const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &status, .{}); |
| 3461 | try std.testing.expectEqual(result.y, 2.5); |
| 3462 | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.5 }, result.x.get(status.zoir.?)); |
| 3463 | } |
| 3464 | |
| 3465 | { |
| 3466 | var status: Status = .{}; |
| 3467 | defer status.deinit(gpa); |
| 3468 | const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &status, .{}); |
| 3469 | try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(status.zoir.?)); |
| 3470 | } |
| 3471 | } |