Commit 35ac35f2
35ac35f26089Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): box obj_X_ptr_array via sp_box_ptr_array in box_expr_to_poly
box_expr_to_poly checked is_obj_type before is_ptr_array_type. Both
predicates fire on obj_<Class>_ptr_array (it both starts with
obj_ and ends with _ptr_array), so the is_obj_type branch ran
first, fed <Class>_ptr_array to find_class_idx (which returned -1
for "no such class"), and emitted
sp_box_obj(p, -1)
-1 happens to equal SP_BUILTIN_INT_ARRAY, so a PtrArray boxed
into a poly slot was mis-tagged as an IntArray at runtime and
subsequent dispatch fell into the wrong branch.
Reorder so the built-in pointer types (int_array, float_array, str_array, sym_array, *_ptr_array via is_ptr_array_type) are checked before the catch-all is_obj_type branch. Mirrors the ordering already used by box_value_to_poly and box_val_to_poly (they were correct from the start; only box_expr_to_poly had this oversight).
Without this, the dispatch added by the previous commit
(fix(codegen): dispatch [] on poly recv that's a PtrArray) is
unreachable — the runtime cls_id never lands on
SP_BUILTIN_PTR_ARRAY.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 35ac35f26089
- Parent
- e96344d85616
spinel_codegen.rbmodifiedView file
if at == "symbol" return "sp_box_sym(" + val + ")" end if is_obj_type(at) == 1 cname = at[4, at.length - 4] ci = find_class_idx(cname) return "sp_box_obj(" + val + ", " + ci.to_s + ")" end # Built-in pointer types: route through sp_box_obj with a reserved # negative cls_id (SP_BUILTIN_*) so dispatch is uniform. # negative cls_id (SP_BUILTIN_*) so dispatch is uniform. These # checks run BEFORE is_obj_type because an `obj_X_ptr_array` type # tag both starts with "obj_" and ends with "_ptr_array" — the # is_obj_type branch would otherwise feed a "Foo_ptr_array" name # to find_class_idx, get -1 (= SP_BUILTIN_INT_ARRAY by accident), # and emit `sp_box_obj(p, -1)` which mis-tags the runtime value. if at == "int_array" return "sp_box_int_array(" + val + ")" end if is_ptr_array_type(at) == 1 return "sp_box_ptr_array(" + val + ")" end if is_obj_type(at) == 1 cname = at[4, at.length - 4] ci = find_class_idx(cname) return "sp_box_obj(" + val + ", " + ci.to_s + ")" end if at == "proc" || at == "lambda" return "sp_box_proc(" + val + ")" endtest/poly_dispatch_ptr_array.rbaddedView file
Loading diff…