Commit 57d25a8b
57d25a8b3530Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): puts on poly-hash element routes through sp_poly_puts
puts hash[k] where hash is sym/str/int/poly_poly_hash returned
sp_RbVal but infer_type reported stale "int", so the int arm
emitted printf("%lld", (long long)<struct>) — C rejects the
struct-to-long-long cast.
compile_puts now peeks the IndexReadNode recv; when it's a
poly-hash (or poly_array) the puts dispatches through sp_poly
_puts. test/hash_shorthand was the canonical trigger (total = {n:, m:, sum: 18} collapses to sym_poly_hash under promote
because the int values widened to bigint).
Promote-mode test: +1 (hash_shorthand passes). Default 631/0/0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 57d25a8b3530
- Parent
- 73905e7e5796
spinel_codegen.rbmodifiedView file
next end val = compile_expr(aid) # `puts hash[k]` where hash is a sym/str/int_poly_hash returns # sp_RbVal but `infer_type` can report stale "int". Detect the # CallNode `[]` against a poly-hash recv so we route through # the poly puts emit rather than the int `printf("%lld", ...)` # arm which would cast a struct to long long. if at != "poly" && aid >= 0 && @nd_type[aid] == "CallNode" && @nd_name[aid] == "[]" idx_recv_p = @nd_receiver[aid] if idx_recv_p >= 0 recv_t_idx_p = base_type(infer_type(idx_recv_p)) if recv_t_idx_p == "sym_poly_hash" || recv_t_idx_p == "str_poly_hash" || recv_t_idx_p == "int_poly_hash" || recv_t_idx_p == "poly_poly_hash" || recv_t_idx_p == "poly_array" at = "poly" end end end if at == "poly" @needs_rb_value = 1 emit(" sp_poly_puts(" + val + ");")