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

@@ -32360,6 +32360,20 @@
3236032360 next
3236132361 end
3236232362 val = compile_expr(aid)
32363+ # `puts hash[k]` where hash is a sym/str/int_poly_hash returns
32364+ # sp_RbVal but `infer_type` can report stale "int". Detect the
32365+ # CallNode `[]` against a poly-hash recv so we route through
32366+ # the poly puts emit rather than the int `printf("%lld", ...)`
32367+ # arm which would cast a struct to long long.
32368+ if at != "poly" && aid >= 0 && @nd_type[aid] == "CallNode" && @nd_name[aid] == "[]"
32369+ idx_recv_p = @nd_receiver[aid]
32370+ if idx_recv_p >= 0
32371+ recv_t_idx_p = base_type(infer_type(idx_recv_p))
32372+ 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"
32373+ at = "poly"
32374+ end
32375+ end
32376+ end
3236332377 if at == "poly"
3236432378 @needs_rb_value = 1
3236532379 emit(" sp_poly_puts(" + val + ");")