mirror of
https://github.com/ziglang/zig.git
synced 2025-12-29 09:33:18 +00:00
stage2: implement Type.onePossibleValue for structs
This commit is contained in:
parent
d47f0abd5b
commit
2f07d76eee
10
src/type.zig
10
src/type.zig
@ -3118,8 +3118,14 @@ pub const Type = extern union {
|
||||
=> return null,
|
||||
|
||||
.@"struct" => {
|
||||
log.warn("TODO implement Type.onePossibleValue for structs", .{});
|
||||
return null;
|
||||
const s = ty.castTag(.@"struct").?.data;
|
||||
for (s.fields.entries.items) |entry| {
|
||||
const field_ty = entry.value.ty;
|
||||
if (field_ty.onePossibleValue() == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return Value.initTag(.empty_struct_value);
|
||||
},
|
||||
|
||||
.empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value),
|
||||
|
||||
@ -524,6 +524,16 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
":6:10: error: no field named 'z' in struct 'Point'",
|
||||
":1:15: note: 'Point' declared here",
|
||||
});
|
||||
case.addCompareOutput(
|
||||
\\const Point = struct { x: i32, y: i32 };
|
||||
\\export fn main() c_int {
|
||||
\\ var p: Point = .{
|
||||
\\ .x = 12,
|
||||
\\ .y = 24,
|
||||
\\ };
|
||||
\\ return p.y - p.x - p.x;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
||||
ctx.c("empty start function", linux_x64,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user