mirror of
https://github.com/ziglang/zig.git
synced 2026-01-24 08:15:23 +00:00
This commit allows using ZON (Zig Object Notation) in a few ways. * `@import` can be used to load ZON at comptime and convert it to a normal Zig value. In this case, `@import` must have a result type. * `std.zon.parse` can be used to parse ZON at runtime, akin to the parsing logic in `std.json`. * `std.zon.stringify` can be used to convert arbitrary data structures to ZON at runtime, again akin to `std.json`.
53 lines
1.1 KiB
Zig
53 lines
1.1 KiB
Zig
const S = struct { x: u32 = 0 };
|
|
const T = struct { []const u8 };
|
|
|
|
fn test0() !void {
|
|
const x: u8 = try 1;
|
|
_ = x;
|
|
}
|
|
|
|
fn test1() !void {
|
|
const x: S = try .{};
|
|
_ = x;
|
|
}
|
|
|
|
fn test2() !void {
|
|
const x: S = try .{ .x = 123 };
|
|
_ = x;
|
|
}
|
|
|
|
fn test3() !void {
|
|
const x: S = try try .{ .x = 123 };
|
|
_ = x;
|
|
}
|
|
|
|
fn test4() !void {
|
|
const x: T = try .{"hello"};
|
|
_ = x;
|
|
}
|
|
|
|
fn test5() !void {
|
|
const x: error{Foo}!u32 = 123;
|
|
_ = try try x;
|
|
}
|
|
|
|
comptime {
|
|
_ = &test0;
|
|
_ = &test1;
|
|
_ = &test2;
|
|
_ = &test3;
|
|
_ = &test4;
|
|
_ = &test5;
|
|
}
|
|
|
|
// error
|
|
//
|
|
// :5:23: error: expected error union type, found 'comptime_int'
|
|
// :10:23: error: expected error union type, found '@TypeOf(.{})'
|
|
// :15:23: error: expected error union type, found 'tmp.test2__struct_494'
|
|
// :15:23: note: struct declared here
|
|
// :20:27: error: expected error union type, found 'tmp.test3__struct_496'
|
|
// :20:27: note: struct declared here
|
|
// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
|
|
// :31:13: error: expected error union type, found 'u32'
|