aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-26 21:22:34 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:56 -0700
commit2d5bc0146941f4cc207c4fd23058e25a16fd40a7 (patch)
tree64087a3ecf4d63d9e53a5f04156dff508d58bd26 /src/type.zig
parentc8b0d4d149c891ed83db57fe6986d10c5dd654af (diff)
downloadzig-2d5bc0146941f4cc207c4fd23058e25a16fd40a7.tar.gz
zig-2d5bc0146941f4cc207c4fd23058e25a16fd40a7.zip
behavior: get more test cases passing with llvm
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/type.zig b/src/type.zig
index a9ad8b94fd..ebf331ef88 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -2481,25 +2481,32 @@ pub const Type = struct {
.struct_type => |struct_type| {
if (mod.structPtrUnwrap(struct_type.index)) |s| {
assert(s.haveFieldTypes());
- for (s.fields.values()) |field| {
- if (field.is_comptime) continue;
- if ((try field.ty.onePossibleValue(mod)) != null) continue;
- return null;
+ const field_vals = try mod.gpa.alloc(InternPool.Index, s.fields.count());
+ defer mod.gpa.free(field_vals);
+ for (field_vals, s.fields.values()) |*field_val, field| {
+ if (field.is_comptime) {
+ field_val.* = try field.default_val.intern(field.ty, mod);
+ continue;
+ }
+ if (try field.ty.onePossibleValue(mod)) |field_opv| {
+ field_val.* = try field_opv.intern(field.ty, mod);
+ } else return null;
}
+
+ // In this case the struct has no runtime-known fields and
+ // therefore has one possible value.
+ return (try mod.intern(.{ .aggregate = .{
+ .ty = ty.toIntern(),
+ .storage = .{ .elems = field_vals },
+ } })).toValue();
}
- // In this case the struct has no runtime-known fields and
- // therefore has one possible value.
- // TODO: this is incorrect for structs with comptime fields, I think
- // we should use a temporary allocator to construct an aggregate that
- // is populated with the comptime values and then intern that value here.
- // This TODO is repeated in the redundant implementation of
- // one-possible-value logic in Sema.zig.
- const empty = try mod.intern(.{ .aggregate = .{
+ // In this case the struct has no fields at all and
+ // therefore has one possible value.
+ return (try mod.intern(.{ .aggregate = .{
.ty = ty.toIntern(),
.storage = .{ .elems = &.{} },
- } });
- return empty.toValue();
+ } })).toValue();
},
.anon_struct_type => |tuple| {