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
end28054+
# Auto-unbox poly RHS into a primitive local slot. Common28055+
# case: `pixel0 = arr[i]` where arr is heterogeneous (poly28056+
# element type) and the dispatch arms all return int —28057+
# spinel types `arr[i]` as poly, but the local is concretely28058+
# int from a prior int-typed write. Reading .v.i preserves28059+
# the runtime int payload; non-int payloads fall to 028060+
# (matches `to_i` semantics for poly).28061+
if rhs_t == "poly" && (vt == "int" || vt == "bool")28062+
val = "(" + val + ").v.i"28063+
end28064+
if rhs_t == "poly" && vt == "float"28065+
val = "(" + val + ").v.f"28066+
end2805428067
emit(" " + vref + " = " + val + ";")2805528068
end2805628069
if rhs_t != "nil" || is_nullable_type(vt) == 0test/auto_unbox_poly_to_int_local.rbaddedView file
Loading diff…
test/auto_unbox_poly_to_int_local.rb.expectedaddedView file
Loading diff…