Commit a99d24e9
a99d24e95c24Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +1 added · ~2 modified
Description
Implement Struct#dig
Struct#dig fell through to an unresolved nil and emitted a C type error. Implement it as a variadic dig: the first key is member access (by symbol/string name or integer position, same resolution as Struct#[]); any further keys dig recursively into the member's value via emit_dig_step's cls_id-aware traversal (so a member holding a hash or array digs correctly). The multi-key result is poly; a single-key result keeps the member's concrete type.
Also gate the array- and hash-method dig handlers on their receiver types: both ran unconditionally and intercepted dig on an object receiver before the object dispatch (emitting nil), which is why Struct#dig never reached the new arm.
This completes the Time/Struct/Object method-gap bundle (J1, J2, J5, J6 were already resolved; J3 added Struct#to_h with a block).
Fixes #1222
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- a99d24e95c24
- Parent
- c20c6a7e0d0b
spinel_analyze.rbmodifiedView file
return "" end rt = infer_type(recv) # Struct#dig(key, ...): the first key is member access, typed as # that member's ivar type. With further keys the result digs deeper # and is dynamic (poly). Mirrors the Struct#[] arm + the codegen # emit_dig_step chain. sci_dg = struct_recv_ci(recv) if sci_dg >= 0 args_id_dg = @nd_arguments[nid] if args_id_dg >= 0 a_dg = get_args(args_id_dg) if a_dg.length >= 1 readers_dg = @cls_attr_readers[sci_dg].split(";", -1) fld_dg = "" if @nd_type[a_dg[0]] == "SymbolNode" || @nd_type[a_dg[0]] == "StringNode" fld_dg = @nd_content[a_dg[0]] elsif @nd_type[a_dg[0]] == "IntegerNode" idx_dg = @nd_value[a_dg[0]].to_i if idx_dg < 0 idx_dg = idx_dg + readers_dg.length end if idx_dg >= 0 && idx_dg < readers_dg.length fld_dg = readers_dg[idx_dg] end end if fld_dg != "" ft_dg = cls_ivar_type(sci_dg, "@" + fld_dg) if ft_dg != "" if a_dg.length == 1 return ft_dg end @needs_rb_value = 1 return "poly" end end end end end # poly_array recv with multi-arg dig: result is sp_RbVal # because the inner step walks a per-element cls_id # dispatch. Issue #555 case 07.spinel_codegen.rbmodifiedView file
Loading diff…
test/struct_dig.rbaddedView file
Loading diff…