| ... | ... | @@ -1094,6 +1094,7 @@ const Parser = struct { |
| 1094 | 1094 | name: []const u8, |
| 1095 | 1095 | ) error{ OutOfMemory, ParseZon } { |
| 1096 | 1096 | @branchHint(.cold); |
| 1097 | if (self.diag == null) return error.ParseZon; |
| 1097 | 1098 | const gpa = self.gpa; |
| 1098 | 1099 | const token = if (field) |f| b: { |
| 1099 | 1100 | var buf: [2]Ast.Node.Index = undefined; |
| ... | ... | @@ -1150,6 +1151,7 @@ const Parser = struct { |
| 1150 | 1151 | field: usize, |
| 1151 | 1152 | ) error{ OutOfMemory, ParseZon } { |
| 1152 | 1153 | @branchHint(.cold); |
| 1154 | if (self.diag == null) return error.ParseZon; |
| 1153 | 1155 | const ast_node = node.getAstNode(self.zoir); |
| 1154 | 1156 | var buf: [2]Ast.Node.Index = undefined; |
| 1155 | 1157 | const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: { |
| ... | ... | @@ -3540,3 +3542,26 @@ test "std.zon no alloc" { |
| 3540 | 3542 | try fromZoirNode(Nested, ast, zoir, .root, null, .{}), |
| 3541 | 3543 | ); |
| 3542 | 3544 | } |
| 3545 | |
| 3546 | test "std.zon errors without diagnostics" { |
| 3547 | const gpa = std.testing.allocator; |
| 3548 | |
| 3549 | const Enum = enum { |
| 3550 | foo, |
| 3551 | bar, |
| 3552 | baz, |
| 3553 | }; |
| 3554 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Enum, gpa, ".nothing", null, .{})); |
| 3555 | |
| 3556 | const Struct = struct { |
| 3557 | name: []const u8, |
| 3558 | }; |
| 3559 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Struct, gpa, ".{ .name = \"Alice\", .age = 25 }", null, .{})); |
| 3560 | |
| 3561 | const Union = union(enum) { |
| 3562 | x, |
| 3563 | y: u32, |
| 3564 | }; |
| 3565 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{})); |
| 3566 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{})); |
| 3567 | } |