Commit 54c24da8

54c24da867aeMerged

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

Description

fix(codegen): override stale cached type for obj.method / bare cmeth calls in promote mode

compile_expr_for_expected_type's post-promotion arithmetic override covered + - * / % etc. but not regular method calls, so a CallNode like @w.grab (where Wrapper#grab's return slot was promoted to bigint) still picked up the stale "int" annotation filled by annotate_all_node_types and got double-wrapped via sp_bigint_new_int.

Extend the override to consult cls_method_return directly when at != bigint:

  • obj.method with an obj-typed recv -> look up the recv's class.
  • bare receiver (target inside a class body) -> look up under @current_class_idx.

Promote-mode test count: 466 pass / 46 fail / 106 error -> 467 pass / 46 fail / 105 error. Default raise mode unchanged at 618 / 0 / 0.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
54c24da867ae
Parent
6ab20447be4f

spinel_codegen.rbmodifiedView file

@@ -5560,6 +5560,32 @@
55605560 end
55615561 end
55625562 end
5563+ # Same shape for an `obj.method` call: cached type may be the
5564+ # pre-promotion "int", but cls_method_return is now bigint after
5565+ # the global promote. Mirror infer_call_type's obj-arm so the
5566+ # emitted call's actual return type drives the coerce decision.
5567+ if at != "bigint" && cm_recv_p >= 0
5568+ recv_t_p = base_type(infer_type(cm_recv_p))
5569+ if is_obj_type(recv_t_p) == 1
5570+ rcname_p = recv_t_p[4, recv_t_p.length - 4]
5571+ rci_p = find_class_idx(rcname_p)
5572+ if rci_p >= 0
5573+ mr_p = cls_method_return(rci_p, cm_mn_p)
5574+ if base_type(mr_p) == "bigint"
5575+ at = "bigint"
5576+ end
5577+ end
5578+ end
5579+ end
5580+ # Bare call inside a class body (recv < 0) — same staleness
5581+ # for `target` inside `def foo(opt = target)` where target's
5582+ # return slot got promoted.
5583+ if at != "bigint" && cm_recv_p < 0 && @current_class_idx >= 0
5584+ mr_b = cls_method_return(@current_class_idx, cm_mn_p)
5585+ if base_type(mr_b) == "bigint"
5586+ at = "bigint"
5587+ end
5588+ end
55635589 end
55645590 # `if v.is_a?(String); helper(v); end` (and analogues for int /
55655591 # float / sym / obj) — `v`'s C storage is sp_RbVal but the