Commit cf52df06

cf52df066aa5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +2 added

Description

Merge pull request #332 from mame/pr/unbox-poly-index-arg

fix(codegen): unbox poly index arg in poly_array []/Method dispatch

Details

Commit
cf52df066aa5
Parent
4e598bc18818
Merge parent
25bec8585625

test/unbox_poly_index_in_dispatch.rbaddedView file

1+# `emit_poly_builtin_dispatch` referenced `arg_types` out of scope.
2+# Without the fix, `(poly_recv)[poly_idx]` produced
3+# `sp_PolyArray_get(arr, sp_RbVal_idx)` — passing sp_RbVal where
4+# mrb_int is expected and failing the C compile.
5+#
6+# Trigger: poly recv (from heterogeneous Hash) + poly idx (also).
7+
8+class C
9+ def initialize
10+ @bag = { "arr" => [100, 200, 300, 400], "lbl" => "x" }
11+ @keys = { "i" => 2, "s" => "lbl" }
12+ end
13+ def at(k)
14+ arr = @bag["arr"] # poly
15+ idx = @keys[k] # poly
16+ arr[idx] # poly recv + poly idx
17+ end
18+end
19+
20+puts C.new.at("i").to_s # use .to_s (handled separately) instead of .to_i