Commit e99ca666

e99ca66646a4Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · ~2 modified

Description

fix(codegen): infer float_array.sum as float, not int

Follow-up to db8307f (PR #24). The dispatch and runtime helper added there emit sp_FloatArray_sum correctly, but infer_method_name_type still returned "int" for sum regardless of receiver, so call sites wrapped the result in (long long) and truncated non-integer-valued sums (e.g. [1.5, 2.5, 0.5].sum printed 4 instead of 4.5).

Mirror the existing min/max shape: when recv is float_array, return "float". Other receivers keep the int default.

Extend test/bm_float_array.rb with [1.5, 2.5, 0.5].sum (= 4.5, deliberately non-integer-valued so the truncation regression would fail loudly if reintroduced).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
e99ca66646a4
Parent
d8e1d0295350

spinel_codegen.rbmodifiedView file

@@ -2157,6 +2157,12 @@
21572157 return "int"
21582158 end
21592159 if mname == "sum"
2160+ if recv >= 0
2161+ rt = infer_type(recv)
2162+ if rt == "float_array"
2163+ return "float"
2164+ end
2165+ end
21602166 return "int"
21612167 end
21622168 if mname == "reverse"