Commit 6ddce222

6ddce222a647Merged

Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): strip nullable ? marker when casting int to obj pointer

compile_typed_call_args casts an int arg to an object-pointer parameter via (sp_<base> *)<expr> but built the base name from the raw param-type string. When the param type was nullable (e.g. obj_BoundMethod?) the cast came out as (sp_BoundMethod? *)0 and the C compiler choked on the stray question mark.

Pre-strip the ? via the existing is_nullable_type / base_type helpers, the same way c_type does, before deriving the C class name.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
6ddce222a647
Parent
ab64a279d511

spinel_codegen.rbmodifiedView file

@@ -27209,8 +27209,15 @@
2720927209 aexpr = compile_expr(arg_ids[k])
2721027210 if at == "int"
2721127211 if is_obj_type(pt) == 1
27212- # Cast int to object pointer
27213- pcname = pt[4, pt.length - 4]
27212+ # Cast int to object pointer. Strip the nullable `?`
27213+ # marker before deriving the C class name — a param
27214+ # type like `obj_BoundMethod?` would otherwise produce
27215+ # `(sp_BoundMethod? *)0` and gcc chokes on the stray `?`.
27216+ pt_base = pt
27217+ if is_nullable_type(pt) == 1
27218+ pt_base = base_type(pt)
27219+ end
27220+ pcname = pt_base[4, pt_base.length - 4]
2721427221 aexpr = "(sp_" + pcname + " *)" + aexpr
2721527222 end
2721627223 end