Commit 333ea257
333ea25766f2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(analyze): bare method-name arg in module body resolves to module cmeth
Closes #512. M.use(h) inside module M body — where the
inner h is a bare reference to M.h — used to infer h as
int (the default for unresolved bare calls). The wrong type
propagated onto M.use's opts parameter and the downstream
opts.length then emitted 0 with a "cannot resolve call to
'length' on int" warning.
Fix in infer_call_type's bare-call branch: when
@current_lexical_scope names a module (and we're not inside
a class scope -- @current_class_idx < 0), look up
<scope>_cls_<mname> in @meth_names. If present, return its
recorded return type. Sibling to the existing
@current_class_idx >= 0 branch above; the cmeth is registered
under that prefixed form by collect_module_with_prefix.
use(h) (where the outer call is also bare) still warns:
the bare-call argument-propagation pass needs a parallel
module-scope lookup to widen the callee's params from the call
site's arg types. Documented inline in the test fixture.
Local: 481 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 333ea25766f2
- Parent
- 3bae3b7b87c2
spinel_analyze.rbmodifiedView file
mr = cls_method_return(@current_class_idx, mname) return mr end # Bare call inside a `module M` body — implicit self is the # module, so `h` resolves to `M.h`. The cmeth is registered as # `<scope>_cls_<name>` in @meth_names by collect_module_with_prefix. # Issue #512: without this, the bare call's return type fell to # `int`, propagated onto the outer call's param, and downstream # `opts.length` failed dispatch on the wrong (int) receiver type. if recv < 0 && @current_lexical_scope != "" && @current_class_idx < 0 full_name = @current_lexical_scope + "_cls_" + mname mi_module = find_method_idx(full_name) if mi_module >= 0 return @meth_return_types[mi_module] end end # proc / Proc.new if mname == "proc"test/bare_arg_in_module_body.rbaddedView file
Loading diff…
test/bare_arg_in_module_body.rb.expectedaddedView file
Loading diff…