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

@@ -90,7 +90,7 @@
9090 handle_not_found(req)
9191 end
9292
93- def entries
93+ def log
9494 @log
9595 end
9696 end
@@ -118,7 +118,7 @@
118118 end
119119
120120 puts "---log---"
121-entries = router.entries
121+entries = router.log
122122 j = 0
123123 while j < entries.length
124124 puts entries[j]