Commit d792672
Fix float truncation in arr_get/dict_get arithmetic
The compiler's static type table claimed arr_get / dict_get / arr_min
/ arr_max / arr_sum always return int. They don't — they're
polymorphic over the element type. The lie made
h sum = arr_get(cur, 1) + rating; # rating is float
compile to Op::AddInt (the typed fast-path), which calls .to_int() on
both operands and silently truncates the float. Caught by a real
ratings aggregator: summing 4.5 + 3.5 + 5.0 returned 12 instead of
13.0 under VM (tree-walk was fine — its eval_expr inspects values at
runtime, not types at compile time). Tree-walk and VM both wrong-but-
in-different-ways for some shapes.
Removed the polymorphic builtins from the int-return list. They now
have no static return type, so any arithmetic that uses them goes
through Op::Add (the polymorphic dispatch) and respects runtime types.
The four other names that legitimately return int regardless of input
(arr_len, len, arr_index_of, arr_contains) stay in the table.
Found while building examples/recommend/recommend.omc — a real movie
recommendation engine over MovieLens ratings (10k → 100k). VM and
tree-walk now agree on hit counts.
92/92 unit tests pass. 43/43 functional examples produce identical
output under tree-walk and VM.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent e434626 commit d792672
1 file changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
137 | 145 | | |
138 | 146 | | |
139 | 147 | | |
140 | | - | |
141 | | - | |
| 148 | + | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
| |||
0 commit comments