Commit 7c5a6a7
committed
[TS] Resolve the compare-to-zero truthiness idiom as ToBoolean for ref-like operands
Front ends lower `if (x)` into `x != 0` / `x != false`, byte-identical to a
genuine loose comparison in the IR. For reference-like operands the numeric
reading diverges from ToBoolean: `undefined != 0` evaluated as
ToNumber(undefined) = NaN != 0 = true, making `undefined` truthy (found by
the differential oracle: And.andOfUnknown(0, undefined) returned 21 where
JS returns 0). A compare of a fake-object or reference operand against
literal zero/false now resolves via mkTruthyExpr; numeric and boolean
operands keep the literal loose-comparison semantics, matching the
convention of the concrete ArkIR interpreter in the hybrid pipeline.1 parent 3df3c83 commit 7c5a6a7
1 file changed
Lines changed: 32 additions & 0 deletions
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
786 | 787 | | |
787 | 788 | | |
788 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
789 | 793 | | |
790 | 794 | | |
791 | 795 | | |
792 | 796 | | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
793 | 800 | | |
794 | 801 | | |
795 | 802 | | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
796 | 828 | | |
797 | 829 | | |
798 | 830 | | |
| |||
0 commit comments