authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-20 11:25:19+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-20 11:59:49+02:00
loga5ac06268972bd7279a1bb928a40d70cc7d515ed
tree2773b5115c1633c303f9527bc4422fe2e68c0b74
parenta2533e6fca0f28aa64717d8e4c13fe6a780b8b15

stage2: make field/array base ptr work at comptime


2 files changed, 17 insertions(+), 9 deletions(-)

src/Sema.zig+16-8
...@@ -5337,11 +5337,15 @@ fn analyzeOptionalPayloadPtr(...@@ -5337,11 +5337,15 @@ fn analyzeOptionalPayloadPtr(
5337 });5337 });
53385338
5339 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| {5339 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| {
5340 if (initializing) {
5341 return sema.addConstant(
5342 child_pointer,
5343 try Value.Tag.opt_payload_ptr.create(sema.arena, pointer_val),
5344 );
5345 }
5340 if (try sema.pointerDeref(block, src, pointer_val, optional_ptr_ty)) |val| {5346 if (try sema.pointerDeref(block, src, pointer_val, optional_ptr_ty)) |val| {
5341 if (!initializing) {5347 if (val.isNull()) {
5342 if (val.isNull()) {5348 return sema.fail(block, src, "unable to unwrap null", .{});
5343 return sema.fail(block, src, "unable to unwrap null", .{});
5344 }
5345 }5349 }
5346 // The same Value represents the pointer to the optional and the payload.5350 // The same Value represents the pointer to the optional and the payload.
5347 return sema.addConstant(5351 return sema.addConstant(
...@@ -5488,11 +5492,15 @@ fn analyzeErrUnionPayloadPtr(...@@ -5488,11 +5492,15 @@ fn analyzeErrUnionPayloadPtr(
5488 });5492 });
54895493
5490 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {5494 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
5495 if (initializing) {
5496 return sema.addConstant(
5497 operand_pointer_ty,
5498 try Value.Tag.eu_payload_ptr.create(sema.arena, pointer_val),
5499 );
5500 }
5491 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {5501 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
5492 if (!initializing) {5502 if (val.getError()) |name| {
5493 if (val.getError()) |name| {5503 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
5494 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
5495 }
5496 }5504 }
54975505
5498 return sema.addConstant(5506 return sema.addConstant(
test/behavior/struct.zig+1-1
...@@ -1222,7 +1222,7 @@ test "anon init through error unions and optionals" {...@@ -1222,7 +1222,7 @@ test "anon init through error unions and optionals" {
1222 };1222 };
12231223
1224 try S.doTheTest();1224 try S.doTheTest();
1225 // comptime try S.doTheTest(); // TODO1225 comptime try S.doTheTest();
1226}1226}
12271227
1228test "anon init through optional" {1228test "anon init through optional" {