authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-14 12:34:33+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-14 12:34:33+02:00
log3eb29f15f537ee79df8f2c4afa0db94ce6137d4c
tree39c9681be2adbdf7f7022203c842037b5e90f373
parent90f2a8d9c5885cdb302757244a5bb2971fdbabe0
parent8937f18a6f8496e011b13cb086b7948b5f1d540e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10849 from sharpobject/sharpobject_fix_json_comptime_fields

std.json: fix compile error for comptime fields

4 files changed, 15 insertions(+), 11 deletions(-)

lib/std/json.zig+1-1
...@@ -1766,7 +1766,7 @@ fn parseInternal(...@@ -1766,7 +1766,7 @@ fn parseInternal(
1766 }1766 }
1767 }1767 }
1768 if (field.is_comptime) {1768 if (field.is_comptime) {
1769 if (!try parsesTo(field.field_type, field.default_value.?, tokens, child_options)) {1769 if (!try parsesTo(field.field_type, @ptrCast(*const field.field_type, field.default_value.?).*, tokens, child_options)) {
1770 return error.UnexpectedValue;1770 return error.UnexpectedValue;
1771 }1771 }
1772 } else {1772 } else {
lib/std/testing.zig+2
...@@ -466,6 +466,8 @@ test {...@@ -466,6 +466,8 @@ test {
466pub fn refAllDecls(comptime T: type) void {466pub fn refAllDecls(comptime T: type) void {
467 if (!builtin.is_test) return;467 if (!builtin.is_test) return;
468 inline for (comptime std.meta.declarations(T)) |decl| {468 inline for (comptime std.meta.declarations(T)) |decl| {
469 if (decl.is_pub and @typeInfo(@TypeOf(@field(T, decl.name))) == .Struct)
470 _ = @hasDecl(@field(T, decl.name), "foo");
469 _ = decl;471 _ = decl;
470 }472 }
471}473}
lib/std/zig/c_translation.zig+1-1
...@@ -166,7 +166,7 @@ pub fn sizeof(target: anytype) usize {...@@ -166,7 +166,7 @@ pub fn sizeof(target: anytype) usize {
166 const array_info = @typeInfo(ptr.child).Array;166 const array_info = @typeInfo(ptr.child).Array;
167 if ((array_info.child == u8 or array_info.child == u16) and167 if ((array_info.child == u8 or array_info.child == u16) and
168 array_info.sentinel != null and168 array_info.sentinel != null and
169 array_info.sentinel.? == 0)169 @ptrCast(*const array_info.child, array_info.sentinel.?).* == 0)
170 {170 {
171 // length of the string plus one for the null terminator.171 // length of the string plus one for the null terminator.
172 return (array_info.len + 1) * @sizeOf(array_info.child);172 return (array_info.len + 1) * @sizeOf(array_info.child);
lib/std/zig/parser_test.zig+11-9
...@@ -585,15 +585,6 @@ test "zig fmt: asm expression with comptime content" {...@@ -585,15 +585,6 @@ test "zig fmt: asm expression with comptime content" {
585 );585 );
586}586}
587587
588test "zig fmt: anytype struct field" {
589 try testCanonical(
590 \\pub const Pointer = struct {
591 \\ sentinel: anytype,
592 \\};
593 \\
594 );
595}
596
597test "zig fmt: array types last token" {588test "zig fmt: array types last token" {
598 try testCanonical(589 try testCanonical(
599 \\test {590 \\test {
...@@ -4148,6 +4139,17 @@ test "zig fmt: container doc comments" {...@@ -4148,6 +4139,17 @@ test "zig fmt: container doc comments" {
4148 );4139 );
4149}4140}
41504141
4142test "zig fmt: anytype struct field" {
4143 try testError(
4144 \\pub const Pointer = struct {
4145 \\ sentinel: anytype,
4146 \\};
4147 \\
4148 , &[_]Error{
4149 .expected_type_expr,
4150 });
4151}
4152
4151test "zig fmt: extern without container keyword returns error" {4153test "zig fmt: extern without container keyword returns error" {
4152 try testError(4154 try testError(
4153 \\const container = extern {};4155 \\const container = extern {};