-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std/json: parse* cannot handle ?noreturn
#19356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
should specify that Discord's Role Tags Structure is incredibly cursed, but alas, I must parse it. And it'd be very convenient to use |
Does test {
const S = struct {
f: @TypeOf(null),
};
const s = S{ .f = null };
try std.testing.expectEqual(null, s.f);
}
const std = @import("std"); |
On a sidenote, this is kinda funny:
But |
Aah no, you cannot have fields of type test {
const S = struct {
f: @TypeOf(null),
};
var s = S{ .f = null };
try std.testing.expectEqual(0, @sizeOf(@TypeOf(S)));
try std.testing.expectEqual(null, s.f);
s = s;
}
const std = @import("std");
Not sure when this changed |
@Hejsil I also think of Regarding |
Correction to my last comment: // compile error:
// argument to function being called at comptime must be comptime-known;
// function returns a comptime-only type '@TypeOf(null)'
pub fn foo(value: bool) @TypeOf(null) {
_ = value;
return null;
}
fn exe(a: anytype) void {
@compileLog(foo(a));
}
test exe {
exe(true);
} I still see no fundamental problem with the idea, and think it would be nicer if this were allowed, i.e. |
Yup, I've been using |
Zig Version
0.12.0-dev.2928+6fddc9cd3
Steps to Reproduce and Observed Behavior
Minimum reproducible example:
Gives the compile-time error:
Expected Behavior
While
noreturn
on its own can't be parsed into,?noreturn
andfn (T: type) type { return union(enum) { x: SomeType, y: T }}
(where T isnoreturn
) are useful. For instance, see Discord's Role Tags Structure, which with anfn Omittable(T)
helper, can be represented asOmittable(?noreturn)
Workaround for now can be to use
enum{}
instead ofnoreturn
, which both represent a type that has 0 possible values. Another workaround is of course to just make a custom type with its ownjsonParse
andjsonStringify
methods.The text was updated successfully, but these errors were encountered: