Commit 313a87a3
313a87a3eb28Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): resolve subclass parent through enclosing module chain
class Sub < Base inside module M recorded cls_parents[Sub] as
the bare Base (the leaf node name), but the parent class was
registered under M_Base to match the same module-prefix chain
that named M_Sub. emit_class_fields later did
find_class_idx(@cls_parents[ci]) to walk inherited fields, the
lookup returned -1, and Sub came out as a struct missing every
field declared on Base.
Resolve the superclass node via const_ref_flat_name first
(handles class Sub < Outer::Base), then walk module_prefix
upwards trying <scope>_<bare> until a registered class matches.
Mirrors how cname itself is resolved at the top of the same
function.
Encountered while compiling optcarrot — class MMC3 < ROM lost
ROM's full struct.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 313a87a3eb28
- Parent
- d920667f4cc7
spinel_codegen.rbmodifiedView file
end end else parent = @nd_name[sp] parent = const_ref_flat_name(sp) if parent == "" parent = @nd_name[sp] end # Resolve the parent class name against the same module-prefix # chain that was used to register the child. `class Sub < Base` # inside `module M` should land on `M_Base` (the registered # name), not bare "Base", or `emit_class_fields` later fails # `find_class_idx` and silently drops every inherited field. if module_prefix != "" && const_ref_is_relative(sp) == 1 if find_class_idx(parent) < 0 mp = module_prefix while mp != "" cand = mp + "_" + parent if find_class_idx(cand) >= 0 parent = cand mp = "" else idx = mp.rindex("_") if idx < 0 mp = "" else mp = mp[0, idx] end end end end end end endtest/subclass_inherits_module_parent.rbaddedView file
Loading diff…