diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-02-20 11:25:19 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-02-20 11:59:49 +0200 |
| commit | a5ac06268972bd7279a1bb928a40d70cc7d515ed (patch) | |
| tree | 2773b5115c1633c303f9527bc4422fe2e68c0b74 | |
| parent | a2533e6fca0f28aa64717d8e4c13fe6a780b8b15 (diff) | |
| download | zig-a5ac06268972bd7279a1bb928a40d70cc7d515ed.tar.gz zig-a5ac06268972bd7279a1bb928a40d70cc7d515ed.zip | |
stage2: make field/array base ptr work at comptime
| -rw-r--r-- | src/Sema.zig | 24 | ||||
| -rw-r--r-- | test/behavior/struct.zig | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index e7220640a0..b196746c84 100644 --- a/src/Sema.zig +++ b/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( diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index a3e8bbdab3..d059cccb60 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -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" { |
