Commit 47f481b4
47f481b46f5eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): open-class Integer dispatch unboxes bigint recv
Open-class methods on Integer (__oc_Integer_*) always emit a
mrb_int self first parameter (see build_params_str at line 9207),
regardless of how the surrounding method body uses arithmetic.
Under promote mode the caller's recv is sp_Bigint*; emit a
sp_bigint_to_int unwrap so the function signature matches.
Picks up: class_method_open_class_call.
Skipped extending infer_open_class_type to bigint receivers -- that changes self-host inference paths and breaks the bootstrap's default-mode regeneration of analyze1.c.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 47f481b46f5e
- Parent
- 128437662376
spinel_codegen.rbmodifiedView file
@@ -21126,7 +21126,7 @@
2112621126
def compile_open_class_dispatch_expr(nid, mname, rc, recv_type)2112721127
# Open class method dispatch on built-in types2112821128
oc_prefix = ""21129-
if recv_type == "int"21129+
if recv_type == "int" || recv_type == "bigint"2113021130
oc_prefix = "__oc_Integer_"2113121131
end2113221132
if recv_type == "string"@@ -21139,11 +21139,19 @@
2113921139
oc_name = oc_prefix + mname2114021140
oc_mi = find_method_idx(oc_name)2114121141
if oc_mi >= 021142+
# Open-class `self` for Integer is always `mrb_int` (see21143+
# build_params_str at line 9207). In promote mode the call site's21144+
# recv is sp_Bigint*; unbox so the function signature matches.21145+
rc_oc = rc21146+
if recv_type == "bigint"21147+
@needs_bigint = 121148+
rc_oc = "sp_bigint_to_int((sp_Bigint *)" + rc + ")"21149+
end2114221150
ca = compile_call_args(nid)2114321151
if ca != ""21144-
return "sp_" + sanitize_name(oc_name) + "(" + rc + ", " + ca + ")"21152+
return "sp_" + sanitize_name(oc_name) + "(" + rc_oc + ", " + ca + ")"2114521153
else21146-
return "sp_" + sanitize_name(oc_name) + "(" + rc + ")"21154+
return "sp_" + sanitize_name(oc_name) + "(" + rc_oc + ")"2114721155
end2114821156
end2114921157
end