Commit 54b4c2ad
54b4c2adcfa0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen(promote): dispatch Range#include? when the poly arg widened
The poly-receiver include? dispatch emitted a SP_BUILTIN_RANGE arm only
when the argument was statically TY_INT. Under promote the membership arg
(case x when Range; x.include?(n)) widens to poly, so no Range arm was
emitted and the dispatch fell to the false default. Add a Range arm in
the poly-arg branch, unboxing the argument with sp_poly_to_i.
Fixes promote-mode poly_recv_range_sym_hash_dispatch.
Default test 992/0/0 and optcarrot checksum 59662 unchanged.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 54b4c2adcfa0
- Parent
- 5b711b99290c
src/codegen_call.cmodifiedView file
@@ -8519,6 +8519,13 @@
85198519
buf_printf(b, " case SP_BUILTIN_SYM_ARRAY: _t%d = sp_IntArray_include((sp_IntArray *)_t%d.v.p, _t%d); break;", tr, tv, atmp[0]);85208520
buf_printf(b, " case SP_BUILTIN_SYM_POLY_HASH: _t%d = sp_SymPolyHash_has_key((sp_SymPolyHash *)_t%d.v.p, _t%d); break;", tr, tv, atmp[0]);85218521
}8522+
else if (at == TY_POLY) {8523+
/* promote: the include? arg widened to poly. A Range receiver8524+
(`case x when Range; x.include?(n)`) tests numeric membership, so8525+
unbox the arg; the PolyArray/PolyPolyHash arms below cover the8526+
container cases. */8527+
buf_printf(b, " case SP_BUILTIN_RANGE: _t%d = sp_range_include((sp_Range *)_t%d.v.p, sp_poly_to_i(_t%d)); break;", tr, tv, atmp[0]);8528+
}85228529
/* PolyArray: box the arg for runtime comparison */85238530
{85248531
int tbox = ++g_tmp;