mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
stage2: make field/array base ptr work at comptime
This commit is contained in:
parent
a2533e6fca
commit
a5ac062689
24
src/Sema.zig
24
src/Sema.zig
@ -5337,11 +5337,15 @@ fn analyzeOptionalPayloadPtr(
|
||||
});
|
||||
|
||||
if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| {
|
||||
if (initializing) {
|
||||
return sema.addConstant(
|
||||
child_pointer,
|
||||
try Value.Tag.opt_payload_ptr.create(sema.arena, pointer_val),
|
||||
);
|
||||
}
|
||||
if (try sema.pointerDeref(block, src, pointer_val, optional_ptr_ty)) |val| {
|
||||
if (!initializing) {
|
||||
if (val.isNull()) {
|
||||
return sema.fail(block, src, "unable to unwrap null", .{});
|
||||
}
|
||||
if (val.isNull()) {
|
||||
return sema.fail(block, src, "unable to unwrap null", .{});
|
||||
}
|
||||
// The same Value represents the pointer to the optional and the payload.
|
||||
return sema.addConstant(
|
||||
@ -5488,11 +5492,15 @@ fn analyzeErrUnionPayloadPtr(
|
||||
});
|
||||
|
||||
if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
|
||||
if (initializing) {
|
||||
return sema.addConstant(
|
||||
operand_pointer_ty,
|
||||
try Value.Tag.eu_payload_ptr.create(sema.arena, pointer_val),
|
||||
);
|
||||
}
|
||||
if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
|
||||
if (!initializing) {
|
||||
if (val.getError()) |name| {
|
||||
return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
|
||||
}
|
||||
if (val.getError()) |name| {
|
||||
return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
|
||||
}
|
||||
|
||||
return sema.addConstant(
|
||||
|
||||
@ -1222,7 +1222,7 @@ test "anon init through error unions and optionals" {
|
||||
};
|
||||
|
||||
try S.doTheTest();
|
||||
// comptime try S.doTheTest(); // TODO
|
||||
comptime try S.doTheTest();
|
||||
}
|
||||
|
||||
test "anon init through optional" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user