Commit c32df635

c32df63587eeMerged

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

Description

fix(codegen): auto-unbox poly RHS into a primitive local slot

pixel0 = arr[i] where arr is heterogeneous (poly element type) and the dispatch arms all return int — spinel types arr[i] as poly, but the local is concretely int from a prior int-typed write. Reading .v.i preserves the runtime int payload (matches to_i semantics for poly).

Mirrors the existing box-when-slot-is-poly direction for the inverse case.

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

Details

Commit
c32df63587ee
Parent
a0e14abe8ff5

spinel_codegen.rbmodifiedView file

@@ -28051,6 +28051,19 @@
2805128051 if vt == "poly" && rhs_t != "" && rhs_t != "poly"
2805228052 val = box_value_to_poly(rhs_t, val)
2805328053 end
28054+ # Auto-unbox poly RHS into a primitive local slot. Common
28055+ # case: `pixel0 = arr[i]` where arr is heterogeneous (poly
28056+ # element type) and the dispatch arms all return int —
28057+ # spinel types `arr[i]` as poly, but the local is concretely
28058+ # int from a prior int-typed write. Reading .v.i preserves
28059+ # the runtime int payload; non-int payloads fall to 0
28060+ # (matches `to_i` semantics for poly).
28061+ if rhs_t == "poly" && (vt == "int" || vt == "bool")
28062+ val = "(" + val + ").v.i"
28063+ end
28064+ if rhs_t == "poly" && vt == "float"
28065+ val = "(" + val + ").v.f"
28066+ end
2805428067 emit(" " + vref + " = " + val + ";")
2805528068 end
2805628069 if rhs_t != "nil" || is_nullable_type(vt) == 0