diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-03 20:05:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-03 20:05:29 -0700 |
| commit | 2ae72c6f091716a4c1a30928dc1a49c9a1ed312a (patch) | |
| tree | 5dffbaf4d43bab0e2a2835fa0b978cc4b738ac36 /src/value.zig | |
| parent | 69d18ad7f05f093b06388877aa4a7b3d6f2664a6 (diff) | |
| download | zig-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.zig | 9 |
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()) { |
