diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-04-15 11:34:04 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-15 11:34:04 +0300 |
| commit | 3723eb7f3164c40c9cb204cb81efeb6ae3f43847 (patch) | |
| tree | 11fa521d0a6bff7ec373740dc394ebd575a29d13 /src/type.zig | |
| parent | 62d717e2ffb1e9a1127652521de57c2e18cf7d3b (diff) | |
| parent | 94fd914e584d466808f40b9eb5fac49c1cc3c66a (diff) | |
| download | zig-3723eb7f3164c40c9cb204cb81efeb6ae3f43847.tar.gz zig-3723eb7f3164c40c9cb204cb81efeb6ae3f43847.zip | |
Merge pull request #11242 from schmee/sema-handle-more-union-errors
stage2: add more union compile errors / improve error messages
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig index 2a19f7375b..b087f7ab23 100644 --- a/src/type.zig +++ b/src/type.zig @@ -5312,6 +5312,50 @@ pub const Type = extern union { } } + pub fn getNodeOffset(ty: Type) i32 { + switch (ty.tag()) { + .enum_full, .enum_nonexhaustive => { + const enum_full = ty.cast(Payload.EnumFull).?.data; + return enum_full.node_offset; + }, + .enum_numbered => return ty.castTag(.enum_numbered).?.data.node_offset, + .enum_simple => { + const enum_simple = ty.castTag(.enum_simple).?.data; + return enum_simple.node_offset; + }, + .@"struct" => { + const struct_obj = ty.castTag(.@"struct").?.data; + return struct_obj.node_offset; + }, + .error_set => { + const error_set = ty.castTag(.error_set).?.data; + return error_set.node_offset; + }, + .@"union", .union_tagged => { + const union_obj = ty.cast(Payload.Union).?.data; + return union_obj.node_offset; + }, + .@"opaque" => { + const opaque_obj = ty.cast(Payload.Opaque).?.data; + return opaque_obj.node_offset; + }, + .atomic_order, + .atomic_rmw_op, + .calling_convention, + .address_space, + .float_mode, + .reduce_op, + .call_options, + .prefetch_options, + .export_options, + .extern_options, + .type_info, + => unreachable, // These need to be resolved earlier. + + else => unreachable, + } + } + /// Asserts the type is an enum. pub fn enumHasInt(ty: Type, int: Value, target: Target) bool { const S = struct { |
