| ... | ... | @@ -2629,52 +2629,52 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty |
| 2629 | 2629 | if (instructions.len == 1) |
| 2630 | 2630 | return instructions[0].ty; |
| 2631 | 2631 | |
| 2632 | | var prev_inst = instructions[0]; |
| 2633 | | for (instructions[1..]) |next_inst| { |
| 2634 | | if (next_inst.ty.eql(prev_inst.ty)) |
| 2632 | var chosen = instructions[0]; |
| 2633 | for (instructions[1..]) |candidate| { |
| 2634 | if (candidate.ty.eql(chosen.ty)) |
| 2635 | 2635 | continue; |
| 2636 | | if (next_inst.ty.zigTypeTag() == .NoReturn) |
| 2636 | if (candidate.ty.zigTypeTag() == .NoReturn) |
| 2637 | 2637 | continue; |
| 2638 | | if (prev_inst.ty.zigTypeTag() == .NoReturn) { |
| 2639 | | prev_inst = next_inst; |
| 2638 | if (chosen.ty.zigTypeTag() == .NoReturn) { |
| 2639 | chosen = candidate; |
| 2640 | 2640 | continue; |
| 2641 | 2641 | } |
| 2642 | | if (next_inst.ty.zigTypeTag() == .Undefined) |
| 2642 | if (candidate.ty.zigTypeTag() == .Undefined) |
| 2643 | 2643 | continue; |
| 2644 | | if (prev_inst.ty.zigTypeTag() == .Undefined) { |
| 2645 | | prev_inst = next_inst; |
| 2644 | if (chosen.ty.zigTypeTag() == .Undefined) { |
| 2645 | chosen = candidate; |
| 2646 | 2646 | continue; |
| 2647 | 2647 | } |
| 2648 | | if (prev_inst.ty.isInt() and |
| 2649 | | next_inst.ty.isInt() and |
| 2650 | | prev_inst.ty.isSignedInt() == next_inst.ty.isSignedInt()) |
| 2648 | if (chosen.ty.isInt() and |
| 2649 | candidate.ty.isInt() and |
| 2650 | chosen.ty.isSignedInt() == candidate.ty.isSignedInt()) |
| 2651 | 2651 | { |
| 2652 | | if (prev_inst.ty.intInfo(self.getTarget()).bits < next_inst.ty.intInfo(self.getTarget()).bits) { |
| 2653 | | prev_inst = next_inst; |
| 2652 | if (chosen.ty.intInfo(self.getTarget()).bits < candidate.ty.intInfo(self.getTarget()).bits) { |
| 2653 | chosen = candidate; |
| 2654 | 2654 | } |
| 2655 | 2655 | continue; |
| 2656 | 2656 | } |
| 2657 | | if (prev_inst.ty.isFloat() and next_inst.ty.isFloat()) { |
| 2658 | | if (prev_inst.ty.floatBits(self.getTarget()) < next_inst.ty.floatBits(self.getTarget())) { |
| 2659 | | prev_inst = next_inst; |
| 2657 | if (chosen.ty.isFloat() and candidate.ty.isFloat()) { |
| 2658 | if (chosen.ty.floatBits(self.getTarget()) < candidate.ty.floatBits(self.getTarget())) { |
| 2659 | chosen = candidate; |
| 2660 | 2660 | } |
| 2661 | 2661 | continue; |
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | | if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) { |
| 2665 | | prev_inst = next_inst; |
| 2664 | if (chosen.ty.zigTypeTag() == .ComptimeInt and candidate.ty.isInt()) { |
| 2665 | chosen = candidate; |
| 2666 | 2666 | continue; |
| 2667 | 2667 | } |
| 2668 | 2668 | |
| 2669 | | if (prev_inst.ty.isInt() and next_inst.ty.zigTypeTag() == .ComptimeInt) { |
| 2669 | if (chosen.ty.isInt() and candidate.ty.zigTypeTag() == .ComptimeInt) { |
| 2670 | 2670 | continue; |
| 2671 | 2671 | } |
| 2672 | 2672 | |
| 2673 | 2673 | // TODO error notes pointing out each type |
| 2674 | | return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty }); |
| 2674 | return self.fail(scope, candidate.src, "incompatible types: '{}' and '{}'", .{ chosen.ty, candidate.ty }); |
| 2675 | 2675 | } |
| 2676 | 2676 | |
| 2677 | | return prev_inst.ty; |
| 2677 | return chosen.ty; |
| 2678 | 2678 | } |
| 2679 | 2679 | |
| 2680 | 2680 | pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst { |