Commit 50106f3c
50106f3cc3dcMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): bare cls method call inside cls body coerces arg types
def self.exists?(id); _adapter_exists_by_id_p(id); end resolved
the bare _adapter_exists_by_id_p call against
@cls_cmeth_names but compiled its args through compile_call_args
(no type coercion). When the sibling cmeth's param type differed
from the caller's arg type (Article#exists? takes sp_RbVal id;
the adapter expects mrb_int), clang errored on the raw pass.
Add compile_call_args_coerced_for_cmeth: reads the sibling cmeth's ptypes and routes each arg through compile_expr_for_expected_type when the expected type needs a coerce (poly<->concrete, hash variant, typed-array, etc.).
#685: 3 hard errors -> 2 remaining (sp_ActionResponse_new args 2,3 where sp_RbVal poly-dispatch result flows into typed const char * constructor param).
Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.
Refs #685
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 50106f3cc3dc
- Parent
- 4e1c20d60507
spinel_codegen.rbmodifiedView file
cmidx_r = 0 while cmidx_r < cmnames_r.length if cmnames_r[cmidx_r] == mname ca_r = compile_call_args(nid) ca_r = compile_call_args_coerced_for_cmeth(nid, @current_class_idx, cmidx_r) owning_r = @cls_names[@current_class_idx] if ca_r == "" return "sp_" + owning_r + "_cls_" + sanitize_name(mname) + "()" 0 end # Like compile_call_args but coerces each arg's type to match the # callee class-method's declared param type. Used by the bare cls # method call path (`_adapter_exists_by_id_p(id)` inside `def self.X`) # which previously emitted raw compile_expr and tripped clang on # poly<->concrete mismatches (#685, Article#exists? -> Article# # _adapter_exists_by_id_p with sp_RbVal arg into mrb_int param). def compile_call_args_coerced_for_cmeth(nid, ci, cmidx) args_id = @nd_arguments[nid] if args_id < 0 return "" end arg_ids = get_args(args_id) if arg_ids.length == 0 return "" end ptypes = cls_cmeth_ptypes_get(ci, cmidx) result = "" k = 0 while k < arg_ids.length if k > 0 result = result + ", " end pt_arg = k < ptypes.length ? ptypes[k] : "" at_arg = infer_type(arg_ids[k]) pt_base_arg = base_type(pt_arg) needs_arg = 0 if pt_arg != "" if pt_base_arg == "bigint" || pt_base_arg == "int" needs_arg = 1 elsif at_arg == "poly" && pt_base_arg != "poly" && pt_base_arg != "" needs_arg = 1 elsif at_arg != "poly" && pt_base_arg == "poly" needs_arg = 1 elsif pt_base_arg == "string" || pt_base_arg == "mutable_str" needs_arg = 1 elsif is_hash_type(pt_base_arg) == 1 || is_array_type(pt_base_arg) == 1 needs_arg = 1 end end if needs_arg == 1 result = result + compile_expr_for_expected_type(arg_ids[k], pt_arg) else result = result + cast_away_volatile_arg(arg_ids[k], compile_expr(arg_ids[k])) end k = k + 1 end result end def compile_call_args(nid) args_id = @nd_arguments[nid] if args_id < 0