Commit 510d2f6c
510d2f6ce314Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): name-based sample shortcut defers when recv isn't an array
infer_method_name_type had a name-based shortcut for sample
that returned int (the Array#sample default) for any non-string/
sym/float-array receiver. That short-circuited before
infer_recv_method_type could see a user-defined sample on an
obj or poly receiver, so calls like box.sample (where Box has
its own sample returning a non-int type) were inferred as int
regardless of the actual return type — and downstream sites that
depended on the inferred type (puts formatter, binop dispatch,
etc.) used the wrong shape.
Match the int_array case explicitly, then return "" (defer) for any other recv type so the user-class lookup path can produce the right return type.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 510d2f6ce314
- Parent
- 300441b5bc36
spinel_codegen.rbmodifiedView file
if rt == "float_array" return "float" end if rt == "int_array" return "int" end # Not an array — recv has a user-defined `sample`. Defer to # the user-class dispatch path instead of returning the # Array#sample default of int. return "" end return "int" endtest/sample_user_method.rbaddedView file
Loading diff…