Commit 9000016d
9000016d8a3fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): cast int local to sp_* when passed as obj-typed call arg
A method returning obj_<C> | nil whose union collapses to
mrb_int upstream leaves the local catching the call declared
mrb_int. Property-access sites on that local
(local.attr_reader) get a runtime cast via
compile_int_class_fallback_expr — but call args that pass the
local to a typed-pointer parameter (f(local) where the param
is sp_<C> *) were previously emitted raw. The asymmetry
produced gcc errors incompatible integer to pointer conversion
on every such call site.
Fix: in compile_call_args_with_defaults' positional-arg branch,
when the param's declared ptype is obj_<C> and the arg's
inferred type is int, insert a (sp_<C> *) cast — the same
shape the property-access path already emits.
Surfaced via Roundhouse's Comment#after_create_commit →
Views::Articles.article(parent) shape, where parent was
caught from a method returning Article | nil.
Fixes #379
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9000016d8a3f
- Parent
- c38448ced0e7
spinel_codegen.rbmodifiedView file
next end end # When the param expects `sp_<C> *` but the arg's static # type is `int` (typically a local catching a method # whose return widened to mrb_int because the union # collapsed somewhere upstream — e.g. # `parent = article` after a `nil.return` narrows # parent's declared type but the call site below still # passes `lv_parent` raw), insert the same cast that # compile_int_class_fallback_expr already inserts at # property-access sites. Without this, gcc errors # `incompatible integer to pointer conversion`. if is_obj_type(ptypes[k]) == 1 arg_at = infer_type(positional_ids[k]) if arg_at == "int" bt_arg = base_type(ptypes[k]) arg_cname = bt_arg[4, bt_arg.length - 4] result = result + "(sp_" + arg_cname + " *)" + compile_expr(positional_ids[k]) k = k + 1 next end end end result = result + compile_expr(positional_ids[k]) elsetest/call_arg_int_to_obj_cast.rbaddedView file
Loading diff…
test/call_arg_int_to_obj_cast.rb.expectedaddedView file
Loading diff…