Commit d56ba8b5
d56ba8b5dcc0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): is_a?(Hash) narrow unboxes to typed-Hash param at call site
compile_typed_call_args dispatched poly args through compile_expr_for_expected_type only when the param's base type was poly/string/array or obj (with poly arg). Hash-typed params fell to the bare compile_expr path and emitted the raw sp_RbVal, which gcc rejected with "passing sp_RbVal to parameter of incompatible type sp_StrStrHash *" (a hard error, not a -Wincompatible-pointer-types warning). Same story for typed-array params.
Extend the dispatch condition so at == "poly" + hash-typed or
array-typed param routes through the unbox path, and add the matching
hash/array arms in compile_expr_for_expected_type that extract the
sp_RbVal's .v.p and cast to the expected pointer type. Same trust
model as the obj_ arm: the runtime is_a? guard establishes that the
value is some hash/array; we trust the variant matches the callee.
Fixes #631.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- d56ba8b5dcc0
- Parent
- d7a62e512691
spinel_codegen.rbmodifiedView file
cname = expected_base[4, expected_base.length - 4] return "((sp_" + cname + " *)(" + val + ").v.p)" end # `if v.is_a?(Hash); helper(v); end` where `helper`'s param has # been monomorphized to a concrete hash variant (str_str_hash, # sym_int_hash, ...). Same unbox shape as the obj_ arm: extract # the sp_RbVal's `.v.p` and cast to the expected hash pointer # type. The runtime is_a?(Hash) guard ensures the cls_id is # some hash; trusting that the variant matches the callee mirrors # how the obj_ arm trusts is_a?(C). Issue #631 (sibling to #448). if is_hash_type(expected_base) == 1 @needs_rb_value = 1 return "((" + c_type(expected_base) + ")(" + val + ").v.p)" end # Same shape for an is_a?(Array)-narrowed slot landing in a # concrete typed-array param (int_array, str_array, poly_array, # any `*_ptr_array`). if is_array_type(expected_base) == 1 @needs_rb_value = 1 return "((" + c_type(expected_base) + ")(" + val + ").v.p)" end end if expected_base == "poly" && at != "poly" return box_value_to_poly(at, val) if k < ptypes.length pt = ptypes[k] pt_base = base_type(pt) if pt_base == "poly" || pt_base == "string" || is_array_type(pt_base) == 1 || (at == "poly" && is_obj_type(pt_base) == 1) if pt_base == "poly" || pt_base == "string" || is_array_type(pt_base) == 1 || (at == "poly" && is_obj_type(pt_base) == 1) || (at == "poly" && is_hash_type(pt_base) == 1) aexpr = compile_expr_for_expected_type(arg_ids[k], pt) if root_constructor_args == 1 aexpr = root_constructor_arg_if_needed(arg_ids[k], aexpr, pt, later_arg_may_gc[k])test/isa_hash_narrow_typed_param.expectedaddedView file
Loading diff…
test/isa_hash_narrow_typed_param.rbaddedView file
Loading diff…