aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-03 20:05:29 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-03 20:05:29 -0700
commit2ae72c6f091716a4c1a30928dc1a49c9a1ed312a (patch)
tree5dffbaf4d43bab0e2a2835fa0b978cc4b738ac36 /src/value.zig
parent69d18ad7f05f093b06388877aa4a7b3d6f2664a6 (diff)
downloadzig-2ae72c6f091716a4c1a30928dc1a49c9a1ed312a.tar.gz
zig-2ae72c6f091716a4c1a30928dc1a49c9a1ed312a.zip
Sema: implement ExportOptions support in `@export`
Also fix switch blocks not emitting their AIR code.
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 4a547c8836..e6ce65a9f4 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -715,6 +715,15 @@ pub const Value = extern union {
};
}
+ /// Asserts the type is an enum type.
+ pub fn toEnum(val: Value, enum_ty: Type, comptime E: type) E {
+ // TODO this needs to resolve other kinds of Value tags rather than
+ // assuming the tag will be .enum_field_index.
+ const field_index = val.castTag(.enum_field_index).?.data;
+ // TODO should `@intToEnum` do this `@intCast` for you?
+ return @intToEnum(E, @intCast(@typeInfo(E).Enum.tag_type, field_index));
+ }
+
/// Asserts the value is an integer.
pub fn toBigInt(self: Value, space: *BigIntSpace) BigIntConst {
switch (self.tag()) {