| author | |
| committer | |
| log | 100efcf8d3e7fb7562d51b011dfaf639bf93c9ba |
| tree | 08eaaf37a83154cb0624ca82f70784a0f79feeb8 |
| parent | b80cad24840700ead20b59734916bf3d4d4ba87c |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 15 insertions(+), 1 deletions(-)
src/Sema.zig+8-1| ... | ... | @@ -22741,7 +22741,14 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 22741 | 22741 | var ptr_info = operand_ty.ptrInfo(mod); |
| 22742 | 22742 | if (flags.const_cast) ptr_info.flags.is_const = false; |
| 22743 | 22743 | if (flags.volatile_cast) ptr_info.flags.is_volatile = false; |
| 22744 | const dest_ty = try sema.ptrType(ptr_info); | |
| 22744 | ||
| 22745 | const dest_ty = blk: { | |
| 22746 | const dest_ty = try sema.ptrType(ptr_info); | |
| 22747 | if (operand_ty.zigTypeTag(mod) == .Optional) { | |
| 22748 | break :blk try mod.optionalType(dest_ty.toIntern()); | |
| 22749 | } | |
| 22750 | break :blk dest_ty; | |
| 22751 | }; | |
| 22745 | 22752 | |
| 22746 | 22753 | if (try sema.resolveValue(operand)) |operand_val| { |
| 22747 | 22754 | return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern()); |
test/behavior/cast.zig+7| ... | ... | @@ -1585,6 +1585,13 @@ test "@constCast without a result location" { |
| 1585 | 1585 | try expect(y.* == 1234); |
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | test "@constCast optional" { | |
| 1589 | const x: u8 = 10; | |
| 1590 | const m: ?*const u8 = &x; | |
| 1591 | const p = @constCast(m); | |
| 1592 | try expect(@TypeOf(p) == ?*u8); | |
| 1593 | } | |
| 1594 | ||
| 1588 | 1595 | test "@volatileCast without a result location" { |
| 1589 | 1596 | var x: i32 = 1234; |
| 1590 | 1597 | const y: *volatile i32 = &x; |