Commit f12e02f9
f12e02f911efMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
codegen: don't raise NoMethodError for int/poly/nil recvs
d541ecb changed the unresolved-call fallback from emitting 0 to raising NoMethodError so genuine "x.unknown_method" sites surface the bug instead of silently producing 0. This broke optcarrot: patterns like
@hook = nil
...
if @hook
@hook.fire(...)
end
infer @hook as int/poly when the assigned class isn't pinnable. The guarded call then raises at runtime even though the guard keeps it dynamically safe.
Gate the raise on a concrete recv type (string, array, hash, obj_*); fall back to silent 0 on int/poly/nil where the dispatch failure usually reflects unpinnable type inference rather than a real typo. The warning still fires so the diagnostic surface is unchanged.
Refs #727
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- f12e02f911ef
- Parent
- 636ac4de0853
spinel_codegen.rbmodifiedView file
# discards the times call) keep working, while genuine # "x.unknown_method" sites surface the bug instead of returning # a silent zero. Issue #727. # # Gate the raise on a *concrete* receiver type. "int" and "poly" # often arise when an ivar / param's type couldn't be inferred # (e.g. `@x = nil` later assigned an obj at runtime); raising # would break the silent-fallback pattern optcarrot etc. depend # on (`@hook && @hook.fire(...)` where @hook starts nil and is # later assigned). Keep the warn for visibility, fall back to # silent 0 on int/poly recvs. warn_unresolved_call(mname, base_type(recv_type)) rb_unr = base_type(recv_type) if rb_unr == "int" || rb_unr == "poly" || rb_unr == "nil" return "0" end @needs_exc_class_hierarchy = 1 "({ sp_raise_cls(\"NoMethodError\", \"undefined method '" + mname + "' for " + base_type(recv_type) + "\"); (mrb_int)0; })" "({ sp_raise_cls(\"NoMethodError\", \"undefined method '" + mname + "' for " + rb_unr + "\"); (mrb_int)0; })" end def compile_block_given_expr