diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-10-05 15:06:14 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-10-06 20:09:45 +0300 |
| commit | 94039d66ed4fecb7defc5deeeedd7afa3b773f0c (patch) | |
| tree | 59e0c2a2033972bdf2ba22a76db7b1236a82dcc5 /src/type.zig | |
| parent | cc89908e826882065eeaa23bb8827fb7d7cd6219 (diff) | |
| download | zig-94039d66ed4fecb7defc5deeeedd7afa3b773f0c.tar.gz zig-94039d66ed4fecb7defc5deeeedd7afa3b773f0c.zip | |
Sema: disallow fieldParentPtr and offsetOf on comptime fields
Comptime fields are tied to the type and behave more like declarations
so these operations cannot return anything useful for them.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig index 1fef525062..7c35eccbe6 100644 --- a/src/type.zig +++ b/src/type.zig @@ -5664,6 +5664,28 @@ pub const Type = extern union { } } + pub fn structFieldIsComptime(ty: Type, index: usize) bool { + switch (ty.tag()) { + .@"struct" => { + const struct_obj = ty.castTag(.@"struct").?.data; + if (struct_obj.layout == .Packed) return false; + const field = struct_obj.fields.values()[index]; + return field.is_comptime; + }, + .tuple => { + const tuple = ty.castTag(.tuple).?.data; + const val = tuple.values[index]; + return val.tag() != .unreachable_value; + }, + .anon_struct => { + const anon_struct = ty.castTag(.anon_struct).?.data; + const val = anon_struct.values[index]; + return val.tag() != .unreachable_value; + }, + else => unreachable, + } + } + pub fn packedStructFieldByteOffset(ty: Type, field_index: usize, target: Target) u32 { const struct_obj = ty.castTag(.@"struct").?.data; assert(struct_obj.layout == .Packed); |
