Commit 2c82182b
2c82182b70bbMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #88 from mame/fix/array-method-non-array-recv
fix(codegen): skip Array method dispatch on non-array receivers
Details
- Commit
- 2c82182b70bb
- Parent
- 22ba670b3567
- Merge parent
- 4099f6bc25f0
spinel_codegen.rbmodifiedView file
@@ -14946,8 +14946,15 @@
1494614946
end1494714947
1494814948
def compile_array_method_expr(nid, mname, rc, recv_type)14949-
# Skip non-array types14950-
if recv_type == "str_int_hash" || recv_type == "str_str_hash"14949+
# Skip non-array types. Without this guard a user class with a14950+
# method whose name happens to overlap an Array method (e.g.14951+
# `def sample`, `def first`) would be dispatched as that Array14952+
# method, with `array_c_prefix` falling back to `IntArray` and14953+
# the receiver pointer used as if it were an `sp_IntArray *`.14954+
# `is_array_type` deliberately omits *_ptr_array (see its14955+
# docstring), so include it explicitly here — Array#length, #[],14956+
# #each, … all work on a ptr_array via `sp_PtrArray_*`.14957+
if is_array_type(recv_type) == 0 && is_ptr_array_type(recv_type) == 01495114958
return ""1495214959
end1495314960
# Array#inspect and Array#to_s (CRuby aliases them for arrays, sotest/array_method_name_clash.rbaddedView file
Loading diff…