Commit c3e7e0a8
c3e7e0a8d3ffMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(analyze): poly-recv narrowing recognizes module-scoped Class.new
Sibling to #513 (af55659). walk_call_sites_for_class_method,
the global AST walker that powers recover_concrete_classes_for_ivar's
poison-vs-narrow decision, matched only ConstantReadNode
receivers (Cname.new(...)). Module-scoped classes whose call
sites are Mod::Cname.new(...) parse as ConstantPathNode
receivers and silently fell through to the not-matched branch,
so the recovery walk returned empty / "?" and the poly-recv
widening fell back to all-classes. Server got pulled into
M::Holder.use's cls_id dispatch table even though no M::Server
was ever assigned to @w, and M::Server#run's port widened back
to sp_RbVal.
Add a ConstantPathNode arm in the receiver match: flatten via
const_ref_flat_name (which uses the same Mod_Class shape
that @cls_names stores) and compare against the target class's
flattened name. M::Holder.new now matches when ci is the M_Holder
entry; the same applies to any module-scoped class targeted by
the recovery walk.
The repro is structurally identical to #513's top-level case,
just wrapped in module M; after the fix M::Server#run keeps
mrb_int lv_port and the dispatch table at the M::Holder.use
emit drops to two arms (cls_id 21 + 22) -- same C shape the
#513 test fixture verifies for the top-level form.
Closes #531
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- c3e7e0a8d3ff
- Parent
- 70cbad41262b
spinel_analyze.rbmodifiedView file
recv_cs = @nd_receiver[nid] cs_mname = @nd_name[nid] match = 0 if recv_cs >= 0 && @nd_type[recv_cs] == "ConstantReadNode" && @nd_name[recv_cs] == cname # Direct `Cname.new(...)` (top-level class) vs module-scoped # `Mod::Cname.new(...)`. cname is the flattened storage form # (e.g. `M_Holder` for `module M; class Holder`), so the # ConstantPathNode receiver has to be flattened the same way # to compare. Without this arm the walker bailed on any # module-scoped class and the poly-recv recovery (af55659) # fell back to all-classes -- M::Server got pulled into the # M::Holder.use dispatch table even though no M::Server is # ever assigned to @w. Issue #531, sibling to #513. recv_match = 0 if recv_cs >= 0 if @nd_type[recv_cs] == "ConstantReadNode" && @nd_name[recv_cs] == cname recv_match = 1 elsif @nd_type[recv_cs] == "ConstantPathNode" && const_ref_flat_name(recv_cs) == cname recv_match = 1 end end if recv_match == 1 if want_new && cs_mname == "new" match = 1 elsif !want_new && cs_mname == meth_nametest/poly_recv_dispatch_narrow_module.rbaddedView file
Loading diff…
test/poly_recv_dispatch_narrow_module.rb.expectedaddedView file
Loading diff…