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

@@ -16972,6 +16972,19 @@
1697216972 # variable, case-when on a Class value. Those need
1697316973 # precomputed ancestor tables (see docs/CLASS-OBJECT.md).
1697416974 if recv_type == "class"
16975+ # Issue #428: `Kernel.<m>(args)` routes to the bare-method
16976+ # dispatch (compile_no_recv_call_expr handles `sleep` /
16977+ # `puts` / `rand` / etc. as zero-receiver calls already).
16978+ # Bare `sleep(...)` works fine; the Kernel-prefixed form
16979+ # was emit-0'd because compile_object_method_expr's
16980+ # recv_type=="class" arms only covered class-introspection
16981+ # methods. CRuby's Kernel includes every method-function
16982+ # we already implement at the bare path, so the redirect
16983+ # is uniform -- no per-method list needed here.
16984+ recv_id_428 = @nd_receiver[nid]
16985+ if recv_id_428 >= 0 && @nd_type[recv_id_428] == "ConstantReadNode" && @nd_name[recv_id_428] == "Kernel"
16986+ return compile_no_recv_call_expr(nid, mname)
16987+ end
1697516988 if mname == "to_s" || mname == "name" || mname == "inspect"
1697616989 @needs_class_table = 1
1697716990 return "sp_class_to_s(" + rc + ")"