diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-02-14 12:34:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-14 12:34:33 +0200 |
| commit | 3eb29f15f537ee79df8f2c4afa0db94ce6137d4c (patch) | |
| tree | 39c9681be2adbdf7f7022203c842037b5e90f373 | |
| parent | 90f2a8d9c5885cdb302757244a5bb2971fdbabe0 (diff) | |
| parent | 8937f18a6f8496e011b13cb086b7948b5f1d540e (diff) | |
| download | zig-3eb29f15f537ee79df8f2c4afa0db94ce6137d4c.tar.gz zig-3eb29f15f537ee79df8f2c4afa0db94ce6137d4c.zip | |
Merge pull request #10849 from sharpobject/sharpobject_fix_json_comptime_fields
std.json: fix compile error for comptime fields
| -rw-r--r-- | lib/std/json.zig | 2 | ||||
| -rw-r--r-- | lib/std/testing.zig | 2 | ||||
| -rw-r--r-- | lib/std/zig/c_translation.zig | 2 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 20 |
4 files changed, 15 insertions, 11 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig index ec3544364f..e9fde26bec 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1766,7 +1766,7 @@ fn parseInternal( } } if (field.is_comptime) { - if (!try parsesTo(field.field_type, field.default_value.?, tokens, child_options)) { + if (!try parsesTo(field.field_type, @ptrCast(*const field.field_type, field.default_value.?).*, tokens, child_options)) { return error.UnexpectedValue; } } else { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index a9874d4df1..1134717c02 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -466,6 +466,8 @@ test { pub fn refAllDecls(comptime T: type) void { if (!builtin.is_test) return; inline for (comptime std.meta.declarations(T)) |decl| { + if (decl.is_pub and @typeInfo(@TypeOf(@field(T, decl.name))) == .Struct) + _ = @hasDecl(@field(T, decl.name), "foo"); _ = decl; } } diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig index 0062b071c2..67eceda937 100644 --- a/lib/std/zig/c_translation.zig +++ b/lib/std/zig/c_translation.zig @@ -166,7 +166,7 @@ pub fn sizeof(target: anytype) usize { const array_info = @typeInfo(ptr.child).Array; if ((array_info.child == u8 or array_info.child == u16) and array_info.sentinel != null and - array_info.sentinel.? == 0) + @ptrCast(*const array_info.child, array_info.sentinel.?).* == 0) { // length of the string plus one for the null terminator. return (array_info.len + 1) * @sizeOf(array_info.child); diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 14b0e8b501..a0cc11ce4b 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -585,15 +585,6 @@ test "zig fmt: asm expression with comptime content" { ); } -test "zig fmt: anytype struct field" { - try testCanonical( - \\pub const Pointer = struct { - \\ sentinel: anytype, - \\}; - \\ - ); -} - test "zig fmt: array types last token" { try testCanonical( \\test { @@ -4148,6 +4139,17 @@ test "zig fmt: container doc comments" { ); } +test "zig fmt: anytype struct field" { + try testError( + \\pub const Pointer = struct { + \\ sentinel: anytype, + \\}; + \\ + , &[_]Error{ + .expected_type_expr, + }); +} + test "zig fmt: extern without container keyword returns error" { try testError( \\const container = extern {}; |
