Commit 631485cd
631485cd1a7bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): route Kernel. cmeth-style calls to bare dispatch (#428)
`Kernel.sleep(seconds)` (and the rest of the Kernel module-function surface) emitted "warning: cannot resolve call to 'sleep' on class (emitting 0)" and silently no-op'd. `compile_object_method_expr`'s recv_type == "class" arm only covered the class-introspection methods (.to_s, ==, ancestors, etc.); arbitrary module-function names fell through to the unresolved-call fallback. Bare `sleep(...)` worked but the Kernel-prefixed form is what users reach for when a `def self.` shadows the Kernel name.
Fix: when the recv AST is the ConstantReadNode "Kernel", route through `compile_no_recv_call_expr`. The bare-dispatch path already handles every Kernel module-function the runtime ships (sleep / puts / print / rand / etc.), so the redirect is uniform -- no per-method whitelist.
Closes #428 Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 631485cd1a7b
- Parent
- 345901d6deea
spinel_codegen.rbmodifiedView file
# variable, case-when on a Class value. Those need # precomputed ancestor tables (see docs/CLASS-OBJECT.md). if recv_type == "class" # Issue #428: `Kernel.<m>(args)` routes to the bare-method # dispatch (compile_no_recv_call_expr handles `sleep` / # `puts` / `rand` / etc. as zero-receiver calls already). # Bare `sleep(...)` works fine; the Kernel-prefixed form # was emit-0'd because compile_object_method_expr's # recv_type=="class" arms only covered class-introspection # methods. CRuby's Kernel includes every method-function # we already implement at the bare path, so the redirect # is uniform -- no per-method list needed here. recv_id_428 = @nd_receiver[nid] if recv_id_428 >= 0 && @nd_type[recv_id_428] == "ConstantReadNode" && @nd_name[recv_id_428] == "Kernel" return compile_no_recv_call_expr(nid, mname) end if mname == "to_s" || mname == "name" || mname == "inspect" @needs_class_table = 1 return "sp_class_to_s(" + rc + ")"test/kernel_module_function_call.rbaddedView file
Loading diff…
test/kernel_module_function_call.rb.expectedaddedView file
Loading diff…