aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-01 17:09:03 -0800
committerAndrew Kelley <andrew@ziglang.org>2022-03-03 15:07:23 -0500
commit7deadf4301d5f5f5e2b8a1a8b2dc7109e2c82181 (patch)
tree9ceee5649ba2b889e2fb8cce3ca08e4b1192e10d /src/value.zig
parent65943010c70b33e711a038dff5f80066045ee1b7 (diff)
downloadzig-7deadf4301d5f5f5e2b8a1a8b2dc7109e2c82181.tar.gz
zig-7deadf4301d5f5f5e2b8a1a8b2dc7109e2c82181.zip
stage2: reify error sets
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig
index d576074ba3..e667c566b9 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -2506,6 +2506,15 @@ pub const Value = extern union {
};
}
+ /// Value of the optional, null if optional has no payload.
+ pub fn optionalValue(val: Value) ?Value {
+ if (val.isNull()) return null;
+
+ // Valid for optional representation to be the direct value
+ // and not use opt_payload.
+ return if (val.castTag(.opt_payload)) |p| p.data else val;
+ }
+
/// Valid for all types. Asserts the value is not undefined.
pub fn isFloat(self: Value) bool {
return switch (self.tag()) {