Commit ad76ddb1

ad76ddb15068Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): puts on stale-int expression that emits bigint

Details

Commit
ad76ddb15068
Parent
76b774cdbbb4

spinel_codegen.rbmodifiedView file

@@ -32359,7 +32359,22 @@
3235932359 end
3236032360
3236132361 # Emit the puts-equivalent for a single arg (extracted for reuse from p).
32362+ # Promote-mode stale-int: an attr_reader / method call returning
32363+ # sp_Bigint * may infer as "int" because the @cls_meth_returns
32364+ # entry was promoted after annotate_all_node_types cached the
32365+ # int. compile_puts and compile_puts_single both run into this:
32366+ # `printf("%lld", (long long)<sp_Bigint*>)` casts a pointer to
32367+ # long long and prints the address. Detect via the unified emit
32368+ # walker and route through the bigint puts arm instead.
32369+ def upgrade_at_for_emit(aid, at)
32370+ if at == "int" && aid >= 0 && expr_emit_is_bigint(aid) == 1
32371+ return "bigint"
32372+ end
32373+ at
32374+ end
32375+
3236232376 def compile_puts_single(aid, at, val)
32377+ at = upgrade_at_for_emit(aid, at)
3236332378 if at == "poly"
3236432379 @needs_rb_value = 1
3236532380 emit(" sp_poly_puts(" + val + ");")
@@ -32406,7 +32421,7 @@
3240632421 k = 0
3240732422 while k < arg_ids.length
3240832423 aid = arg_ids[k]
32409- at = infer_type(aid)
32424+ at = upgrade_at_for_emit(aid, infer_type(aid))
3241032425 # Issue #640: `puts cond ? :sym : int` ternary's unify_return_type
3241132426 # picks one arm's type (e.g. "symbol") and the other arm's emit
3241232427 # gets dispatched through the wrong puts variant — `sp_sym_to_s