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

@@ -20721,7 +20721,13 @@
2072120721 mi = 0
2072220722 while mi < mnames.length
2072320723 mname = mnames[mi]
20724- if mname != ""
20724+ # `initialize` is excluded: it is not dynamically dispatched on an
20725+ # existing object the way the #567 `[]=` case is -- each class's
20726+ # `.new` calls its own `initialize` directly. Unifying initialize
20727+ # params by position across the hierarchy lets a parent default
20728+ # (e.g. `opts = nil` -> poly) poison an unrelated override param
20729+ # (e.g. `id = 0`), forcing a concrete int param to poly. Issue #1263.
20730+ if mname != "" && mname != "initialize"
2072520731 base_pt = cls_meth_ptypes_get(ci, mi)
2072620732 fam_owners = []
2072720733 fam_midxs = []