Commit 5abbddde
5abbddde00c0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
codegen: raise NoMethodError on unresolved method calls
The fallthrough at the bottom of method dispatch silently emitted 0 when no arm matched. With method_missing not supported, the call should fail loudly at runtime instead of producing a confused zero.
Replace the bare "0" return with a statement-expression that calls sp_raise_cls("NoMethodError", "undefined method '' for ") and yields 0. The raise only fires when the expression is actually evaluated -- chain-recognition arms (e.g. `4.times.map { ... }` which generates its own for-loop and discards the .times call) already build their result without consulting the receiver expression, so they keep working; genuine "x.unknown_method" sites surface the bug.
Existing 476-test suite still green; behaviour change is only for sites that were silently returning 0.
Fixes #727
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 5abbddde00c0
- Parent
- 36ecd4b9c187
spinel_codegen.rbmodifiedView file
# Unresolved method call on a known receiver. None of the dispatch # branches above claimed the shape — typical causes: typo in the # method name, missing def on the receiver class, or a Ruby idiom # Spinel doesn't support yet. Warn loud at codegen so the user # sees the problem instead of just getting a silently-zero-valued # binary; emit `0` as the C expression so existing call sites that # genuinely rely on the silent fallback (the instance_eval # trampoline body, partially-implemented features whose bench/test # outputs happen to coincide with `0`) keep compiling. Hard fail # would catch more typos but tear up those existing patterns. # Spinel doesn't support yet. Warn loud at codegen and bake a # runtime NoMethodError raise into the expression itself via a # statement-expression. The raise only fires when the expression # is actually evaluated -- so chain-recognition arms (e.g. # `4.times.map { ... }` which generates its own for-loop and # discards the times call) keep working, while genuine # "x.unknown_method" sites surface the bug instead of returning # a silent zero. Issue #727. warn_unresolved_call(mname, base_type(recv_type)) "0" @needs_exc_class_hierarchy = 1 "({ sp_raise_cls(\"NoMethodError\", \"undefined method '" + mname + "' for " + base_type(recv_type) + "\"); (mrb_int)0; })" end def compile_block_given_expr