Commit 8ad869e5

8ad869e58a58Merged

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

Description

fix(codegen): poly_array << / push handlers in both expr and stmt context

compile_call_expr and compile_mutating_call_stmt had << / push branches for int_array, float_array, str_array, sym_array, ptr_array, but not poly_array — so arr << val on a poly_array recv fell through to:

  • (expr context, line 20744) raw C << operator: (arr << val) where arr is sp_PolyArray * and val is sp_Method *. gcc rejects with "invalid operands to binary <<".
  • (stmt context, no fall-through) silently dropped — the push vanished from the generated C entirely.

Add poly_array branches in both:

  • expr context: (sp_PolyArray_push(rc, box(val)), rc)
  • stmt context: sp_PolyArray_push(rc, box(val));

The argument is boxed via box_value_to_poly when its static type is non-poly so the PolyArray's elements stay typed as sp_RbVal (PolyArray's element representation).

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

Details

Commit
8ad869e58a58
Parent
ef05cb1aa590

spinel_codegen.rbmodifiedView file

@@ -21595,6 +21595,12 @@
2159521595 rc = compile_expr_gc_rooted(recv)
2159621596 return "(sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
2159721597 end
21598+ if lt == "poly_array"
21599+ @needs_rb_value = 1
21600+ @needs_gc = 1
21601+ rc = compile_expr_gc_rooted(recv)
21602+ return "(sp_PolyArray_push(" + rc + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + "), " + rc + ")"
21603+ end
2159821604 if lt == "poly"
2159921605 @needs_rb_value = 1
2160021606 return "sp_poly_shl(" + compile_expr(recv) + ", " + box_expr_to_poly(get_args(@nd_arguments[nid])[0]) + ")"
@@ -28683,6 +28689,22 @@
2868328689 emit(" sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + ");")
2868428690 return 1
2868528691 end
28692+ if rt == "poly_array"
28693+ rc = compile_expr_gc_rooted(recv)
28694+ args_id3 = @nd_arguments[nid]
28695+ if args_id3 >= 0
28696+ aa = get_args(args_id3)
28697+ if aa.length > 0
28698+ vt = infer_type(aa[0])
28699+ vexpr = compile_expr(aa[0])
28700+ if vt != "poly"
28701+ vexpr = box_value_to_poly(vt, vexpr)
28702+ end
28703+ emit(" sp_PolyArray_push(" + rc + ", " + vexpr + ");")
28704+ return 1
28705+ end
28706+ end
28707+ end
2868628708 end
2868728709 end
2868828710