| author | |
| committer | |
| log | 2f07d76eee37442f53c294f53b38b11dfb1cd4da |
| tree | 88e02f45de5dc196ef26ce72cf19d68ea187bbde |
| parent | d47f0abd5b5ba95bacd2d573aeabcc53db8c8fc3 |
2 files changed, 18 insertions(+), 2 deletions(-)
src/type.zig+8-2| ... | @@ -3118,8 +3118,14 @@ pub const Type = extern union { | ... | @@ -3118,8 +3118,14 @@ pub const Type = extern union { |
| 3118 | => return null, | 3118 | => return null, |
| 3119 | 3119 | ||
| 3120 | .@"struct" => { | 3120 | .@"struct" => { |
| 3121 | log.warn("TODO implement Type.onePossibleValue for structs", .{}); | 3121 | const s = ty.castTag(.@"struct").?.data; |
| 3122 | return null; | 3122 | for (s.fields.entries.items) |entry| { |
| 3123 | const field_ty = entry.value.ty; | ||
| 3124 | if (field_ty.onePossibleValue() == null) { | ||
| 3125 | return null; | ||
| 3126 | } | ||
| 3127 | } | ||
| 3128 | return Value.initTag(.empty_struct_value); | ||
| 3123 | }, | 3129 | }, |
| 3124 | 3130 | ||
| 3125 | .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value), | 3131 | .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value), |
test/stage2/cbe.zig+10| ... | @@ -524,6 +524,16 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -524,6 +524,16 @@ pub fn addCases(ctx: *TestContext) !void { |
| 524 | ":6:10: error: no field named 'z' in struct 'Point'", | 524 | ":6:10: error: no field named 'z' in struct 'Point'", |
| 525 | ":1:15: note: 'Point' declared here", | 525 | ":1:15: note: 'Point' declared here", |
| 526 | }); | 526 | }); |
| 527 | case.addCompareOutput( | ||
| 528 | \\const Point = struct { x: i32, y: i32 }; | ||
| 529 | \\export fn main() c_int { | ||
| 530 | \\ var p: Point = .{ | ||
| 531 | \\ .x = 12, | ||
| 532 | \\ .y = 24, | ||
| 533 | \\ }; | ||
| 534 | \\ return p.y - p.x - p.x; | ||
| 535 | \\} | ||
| 536 | , ""); | ||
| 527 | } | 537 | } |
| 528 | 538 | ||
| 529 | ctx.c("empty start function", linux_x64, | 539 | ctx.c("empty start function", linux_x64, |