| author | |
| committer | |
| log | ea18f894f524fdc82dc09ea9c6abf8feb93b04e8 |
| tree | f909625161a772e6fff87fd776f5ede1a1a97325 |
| parent | 03113d92467a99658c2606a21821b28b19dfdded |
| signature |
2 files changed, 15 insertions(+), 4 deletions(-)
src/stage1/ir.cpp+6-4| ... | ... | @@ -12706,11 +12706,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12706 | 12706 | } |
| 12707 | 12707 | |
| 12708 | 12708 | if (prev_type->id == ZigTypeIdInt && |
| 12709 | cur_type->id == ZigTypeIdInt && | |
| 12710 | prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) | |
| 12709 | cur_type->id == ZigTypeIdInt) | |
| 12711 | 12710 | { |
| 12712 | if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) { | |
| 12713 | prev_inst = cur_inst; | |
| 12711 | if ((prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) || | |
| 12712 | (cur_type->data.integral.is_signed && !prev_type->data.integral.is_signed)) { | |
| 12713 | if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) { | |
| 12714 | prev_inst = cur_inst; | |
| 12715 | } | |
| 12714 | 12716 | } |
| 12715 | 12717 | continue; |
| 12716 | 12718 | } |
test/stage1/behavior/cast.zig+9| ... | ... | @@ -869,6 +869,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { |
| 869 | 869 | comptime expect(@TypeOf("hi", slice) == [:0]const u8); |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | test "peer type unsigned int to signed" { | |
| 873 | var w: u31 = 5; | |
| 874 | var x: u8 = 7; | |
| 875 | var y: i32 = -5; | |
| 876 | var a = w + y + x; | |
| 877 | comptime expect(@TypeOf(a) == i32); | |
| 878 | expect(a == 7); | |
| 879 | } | |
| 880 | ||
| 872 | 881 | test "peer type resolve array pointers, one of them const" { |
| 873 | 882 | var array1: [4]u8 = undefined; |
| 874 | 883 | const array2: [5]u8 = undefined; |