Commit 346dbf87
346dbf87980dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 8 files · +2 added · ~4 modified · -2 deleted
Description
Revert method_missing dispatch; warn when it is defined instead
Routing an unresolved object call to method_missing (PR #1505) only fired for a statically-concrete, pointer-backed receiver and only for the canonical (name)/(name, *args) shape with a scalar return. A poly receiver, a value-type receiver, a keyword/splat/block call shape, a non-scalar return, or a fixed-arity method_missing all silently fell through to the unresolved diagnostic. Whether method_missing fired thus depended on type inference and call shape (the #1367 inference- sensitivity class), so the same source could route or not based on unrelated program structure.
Full consistency would require dispatching every unresolved call (any arity, kwargs, block, object/container return) through a runtime path, which is foreign to the whole-program AOT model and erodes the dead-strip and specialization that give spinel its size and speed. A half-honored method_missing is worse than a predictably-unsupported one, so revert the routing entirely.
In its place, emit a compile-time warning when a class defines method_missing, so the author is not misled: undefined-method calls raise NoMethodError as before, but the method is still callable explicitly.
This reverts eac9345e (PR #1505) and documents the behavior in docs/limitations.md.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 346dbf87980d
- Parent
- 6a4941cd5d8b
docs/limitations.mdmodifiedView file
| Feature | Behaviour | Why it's fundamental ||---|---|---|| `eval` / `instance_eval("str")` / `class_eval("str")` | unsupported | needs a runtime parser + type system. (Block forms — `instance_eval { }` — DO work; the block is compiled.) || `method_missing` on an arbitrary receiver | unresolved call → stub | every call site is a direct C call; there is no per-receiver dispatch fallback || `method_missing` | not dispatched (defining it warns at compile time) | every call site is a direct C call; an undefined-method call can't fall back to a per-receiver hook. The method is still callable explicitly. || `define_method` with a runtime-computed name/body | only literal names work | a runtime-built method has no compiled body || `ObjectSpace` (`each_object`, `count_objects`) | unsupported | no class-keyed allocation registry; the GC tracks bytes, not a live-object index || `TracePoint` / `set_trace_func` / `binding` | unsupported | require an interpreter loop and reified local scopes |src/analyze.cmodifiedView file
Loading diff…
src/analyze_infer.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…
test/method_missing_basic.rbdeleted
Loading diff…
test/method_missing_basic.rb.expecteddeleted
Loading diff…
test/method_missing_explicit.rbaddedView file
Loading diff…
test/method_missing_explicit.rb.expectedaddedView file
Loading diff…