diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-10-29 15:18:07 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-10-29 19:44:35 +0300 |
| commit | 7705a4e8651a493590eed5a79d5361bc6b54985e (patch) | |
| tree | c9c834441f236f358d87734b1e56010acbaeb80a /src | |
| parent | 278c32976e93f4900c634913fb2bb06f6a7ecf87 (diff) | |
| download | zig-7705a4e8651a493590eed5a79d5361bc6b54985e.tar.gz zig-7705a4e8651a493590eed5a79d5361bc6b54985e.zip | |
Sema: wrap optionals in `zirPtrCast` when needed
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 7be0336d8f..5aa3c8b700 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -18947,6 +18947,9 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air if (!dest_ty.ptrAllowsZero() and operand_val.isNull()) { return sema.fail(block, operand_src, "null pointer casted to type {}", .{dest_ty.fmt(sema.mod)}); } + if (dest_ty.zigTypeTag() == .Optional and sema.typeOf(ptr).zigTypeTag() != .Optional) { + return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, operand_val)); + } return sema.addConstant(aligned_dest_ty, operand_val); } |
