| author | |
| committer | |
| log | 4d50bc3f8dd2b9fd5b7dde6f63f104aaba6dbf5a |
| tree | 57890fd7b757fd39103327ffd05d1f4352d21128 |
| parent | 89953ec83d8afe4fed0fc9e3cdded09c7522bf86 |
| signature |
closes #12983 files changed, 31 insertions(+), 0 deletions(-)
doc/langref.html.in+7| ... | @@ -4695,6 +4695,13 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { | ... | @@ -4695,6 +4695,13 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| 4695 | 4695 | ||
| 4696 | return slice[0..1]; | 4696 | return slice[0..1]; |
| 4697 | } | 4697 | } |
| 4698 | |||
| 4699 | test "peer type resolution: *const T and ?*T" { | ||
| 4700 | const a = @intToPtr(*const usize, 0x123456789); | ||
| 4701 | const b = @intToPtr(?*usize, 0x123456789); | ||
| 4702 | assert(a == b); | ||
| 4703 | assert(b == a); | ||
| 4704 | } | ||
| 4698 | {#code_end#} | 4705 | {#code_end#} |
| 4699 | {#header_close#} | 4706 | {#header_close#} |
| 4700 | {#header_close#} | 4707 | {#header_close#} |
src/ir.cpp+17| ... | @@ -9658,6 +9658,23 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -9658,6 +9658,23 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9658 | continue; | 9658 | continue; |
| 9659 | } | 9659 | } |
| 9660 | 9660 | ||
| 9661 | if (prev_type->id == ZigTypeIdOptional && | ||
| 9662 | types_match_const_cast_only(ira, cur_type, prev_type->data.maybe.child_type, | ||
| 9663 | source_node, false).id == ConstCastResultIdOk) | ||
| 9664 | { | ||
| 9665 | prev_inst = cur_inst; | ||
| 9666 | any_are_null = true; | ||
| 9667 | continue; | ||
| 9668 | } | ||
| 9669 | |||
| 9670 | if (cur_type->id == ZigTypeIdOptional && | ||
| 9671 | types_match_const_cast_only(ira, prev_type, cur_type->data.maybe.child_type, | ||
| 9672 | source_node, false).id == ConstCastResultIdOk) | ||
| 9673 | { | ||
| 9674 | any_are_null = true; | ||
| 9675 | continue; | ||
| 9676 | } | ||
| 9677 | |||
| 9661 | if (cur_type->id == ZigTypeIdUndefined) { | 9678 | if (cur_type->id == ZigTypeIdUndefined) { |
| 9662 | continue; | 9679 | continue; |
| 9663 | } | 9680 | } |
test/stage1/behavior/pointers.zig+7| ... | @@ -130,3 +130,10 @@ test "initialize const optional C pointer to null" { | ... | @@ -130,3 +130,10 @@ test "initialize const optional C pointer to null" { |
| 130 | expect(a == null); | 130 | expect(a == null); |
| 131 | comptime expect(a == null); | 131 | comptime expect(a == null); |
| 132 | } | 132 | } |
| 133 | |||
| 134 | test "compare equality of optional and non-optional pointer" { | ||
| 135 | const a = @intToPtr(*const usize, 0x123456789); | ||
| 136 | const b = @intToPtr(?*usize, 0x123456789); | ||
| 137 | expect(a == b); | ||
| 138 | expect(b == a); | ||
| 139 | } |