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) == 127212-
# Cast int to object pointer27213-
pcname = pt[4, pt.length - 4]27212+
# Cast int to object pointer. Strip the nullable `?`27213+
# marker before deriving the C class name — a param27214+
# type like `obj_BoundMethod?` would otherwise produce27215+
# `(sp_BoundMethod? *)0` and gcc chokes on the stray `?`.27216+
pt_base = pt27217+
if is_nullable_type(pt) == 127218+
pt_base = base_type(pt)27219+
end27220+
pcname = pt_base[4, pt_base.length - 4]2721427221
aexpr = "(sp_" + pcname + " *)" + aexpr2721527222
end2721627223
endtest/strip_nullable_int_cast.rbaddedView file
Loading diff…
test/strip_nullable_int_cast.rb.expectedaddedView file
Loading diff…