Commit 31855b5e
31855b5ea404Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze): Math. inference only fires when recv is Math
infer_math_and_misc_type matched on the method name alone for the
Math module's sqrt / cos / sin / tan / log / etc.,
returning "float" regardless of receiver. A user-defined method
sharing a Math name (e.g. def log; @log; end on a Router class)
then misinferred as float, and downstream router.log[i]
emitted a float bit-index instead of a str_array read.
Codegen-side compile_constant_recv_expr's Math branch is
already guarded by if rcname == "Math", so the C emit was
correct; the bug lived entirely in analyze's type inference.
Fix: wrap the math-name dispatch in
recv < 0 || (recv is ConstantReadNode for "Math"). The bare-
call form (no recv) keeps working because Ruby's Kernel mix-in
includes Math methods in the global scope, and spinel emits
those through the same libm wrappers. Non-Math receivers
fall through to infer_recv_method_type which resolves the
real user-defined method's return type.
Side effect: bm_sinatra_mini can drop its entries rename
workaround and use the natural def log accessor. Restored.
Validation: tests 454 + new method_named_log_no_math_collision regression (Notebook#log returning str_array + Math.log(1.0) returning float, both in the same file), bench 57/57, bootstrap 4-way fixpoint OK.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 31855b5ea404
- Parent
- 6b098f972cd6
benchmark/bm_sinatra_mini.rbmodifiedView file
handle_not_found(req) end def entries def log @log endendendputs "---log---"entries = router.entriesentries = router.logj = 0while j < entries.length puts entries[j]spinel_analyze.rbmodifiedView file
Loading diff…
test/method_named_log_no_math_collision.rbaddedView file
Loading diff…
test/method_named_log_no_math_collision.rb.expectedaddedView file
Loading diff…