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

@@ -4979,7 +4979,34 @@
49794979 end
49804980 end
49814981 else
4982- parent = @nd_name[sp]
4982+ parent = const_ref_flat_name(sp)
4983+ if parent == ""
4984+ parent = @nd_name[sp]
4985+ end
4986+ # Resolve the parent class name against the same module-prefix
4987+ # chain that was used to register the child. `class Sub < Base`
4988+ # inside `module M` should land on `M_Base` (the registered
4989+ # name), not bare "Base", or `emit_class_fields` later fails
4990+ # `find_class_idx` and silently drops every inherited field.
4991+ if module_prefix != "" && const_ref_is_relative(sp) == 1
4992+ if find_class_idx(parent) < 0
4993+ mp = module_prefix
4994+ while mp != ""
4995+ cand = mp + "_" + parent
4996+ if find_class_idx(cand) >= 0
4997+ parent = cand
4998+ mp = ""
4999+ else
5000+ idx = mp.rindex("_")
5001+ if idx < 0
5002+ mp = ""
5003+ else
5004+ mp = mp[0, idx]
5005+ end
5006+ end
5007+ end
5008+ end
5009+ end
49835010 end
49845011 end
49855012