Commit d9cf0350
d9cf0350f159Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Keep subclass initialize params out of override poly-unification
unify_imeth_override_ptypes widens a method parameter to poly across the
whole inheritance family when any member is poly. That is correct for
dynamically dispatched methods -- a base []= body calling self[k]=v
must reach a wider override (issue #567) -- but initialize is not
dispatched that way: each class's .new calls its own initialize
directly. Unifying initialize params by position let a parent default like
opts = nil (poly) widen an unrelated override param like id = 0,
forcing a concrete int parameter to poly and emitting an invalid
mrb_int = sp_RbVal ivar assignment that fails the C compile.
Exclude initialize from the override-param unification so each
constructor keeps its own precise parameter types.
Fixes #1263
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- d9cf0350f159
- Parent
- 6d300505ba93
spinel_analyze.rbmodifiedView file
mi = 0 while mi < mnames.length mname = mnames[mi] if mname != "" # `initialize` is excluded: it is not dynamically dispatched on an # existing object the way the #567 `[]=` case is -- each class's # `.new` calls its own `initialize` directly. Unifying initialize # params by position across the hierarchy lets a parent default # (e.g. `opts = nil` -> poly) poison an unrelated override param # (e.g. `id = 0`), forcing a concrete int param to poly. Issue #1263. if mname != "" && mname != "initialize" base_pt = cls_meth_ptypes_get(ci, mi) fam_owners = [] fam_midxs = []test/initialize_override_param_inference.rbaddedView file
Loading diff…