Commit 98bf2558
98bf255871b4Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): unbox poly elements when emitting an IntArray literal
`compile_array_literal`'s IntArray branch emitted `sp_IntArray_push(arr, compile_expr(elem))` without consulting the element's inferred type. When the element was poly (sp_RbVal, e.g. optcarrot's CPU#add_mappings does `addr = [addr]` after unify-to-poly widened addr to poly), the push got handed a sp_RbVal struct and gcc rejected with "incompatible type for argument 2 of sp_IntArray_push".
Extract the int payload via `.v.i` when the element type is `poly`. The runtime tag is not checked; we trust the surrounding code to keep the array element typed correctly. A real fix would either (a) widen the array literal itself to a poly_array when any element is poly, or (b) emit a runtime type check. This unboxing is the simpler match for optcarrot's add_mappings shape where the caller code knows the addr is integer at runtime.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 98bf255871b4
- Parent
- bee7e89d5b64
spinel_codegen.rbmodifiedView file
emit(" sp_IntArray *" + tmp + " = sp_IntArray_new();") k = 0 while k < elems.length emit(" sp_IntArray_push(" + tmp + ", " + compile_expr(elems[k]) + ");") ev = compile_expr(elems[k]) et = infer_type(elems[k]) # Unbox poly values when pushing into a (concrete) IntArray. # An ArrayNode literal whose elements are poly (e.g. # `[addr]` where addr's recorded type is sp_RbVal) needs the # int payload extracted via `.v.i`. Without this, the C # compiler rejects the push with "incompatible type". if et == "poly" ev = "(" + ev + ").v.i" end emit(" sp_IntArray_push(" + tmp + ", " + ev + ");") k = k + 1 end tmptest/array_lit_unbox_poly.rbaddedView file
Loading diff…