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

@@ -2953,6 +2953,13 @@
29532953 if rt == "float_array"
29542954 return "float"
29552955 end
2956+ if rt == "int_array"
2957+ return "int"
2958+ end
2959+ # Not an array — recv has a user-defined `sample`. Defer to
2960+ # the user-class dispatch path instead of returning the
2961+ # Array#sample default of int.
2962+ return ""
29562963 end
29572964 return "int"
29582965 end