Commit 24e6a84a
24e6a84a7b96Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): user-defined find/fetch wins over built-in dispatch
infer_method_name_type's find / fetch branches returned "int"
unconditionally for receivers that didn't match a known built-in
collection (str_array, float_array, str_*_hash). For a class
receiver like Bag.find(id) — the canonical ActiveRecord finder
shape — that "int" preempted the later user-defined class-method
dispatch (line 3245+), which would have correctly inferred the
body's return type. puts Bag.find(1) then formatted the
const char * result with %lld and printed garbage; s = Bag.find(1) pinned lv_s as mrb_int and failed to compile.
Return "" instead of "int" in the unmatched-receiver path so the
dispatch chain continues to infer_constant_recv_type, which handles
the user-defined *_cls_<method> lookup correctly. The built-in
collection paths (str_array.find, str_int_hash.fetch, ...) keep
their existing concrete returns; only the fallback changes.
Same family as #127 (module-class-method String return mis-inferred as Integer).
Closes #204
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 24e6a84a7b96
- Parent
- 382796cd0226
spinel_codegen.rbmodifiedView file
return "string" end end return "int" # Issue #204: don't claim "int" for fetch on receivers we don't # recognize as a built-in collection — let later dispatch resolve # a user-defined `def fetch` against the receiver class. return "" end if mname == "has_key?" || mname == "key?" || mname == "member?" return "bool" return "string" end end return "int" # Issue #204: same as fetch above — fall through so a user- # defined `def find` (canonical ActiveRecord finder shape) wins # over the built-in collection dispatch when the receiver isn't # a built-in collection. return "" end if mname == "keys" if recv >= 0test/issue204_user_find_fetch.rbaddedView file
Loading diff…