Commit 3a9e73d8

3a9e73d804acMerged

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

Description

test: collapse 4 empty_array_* tests into one empty_array_param.rb

Issues #58 + #84: empty [] literal as a method parameter, the deferred element-type resolution must converge across caller / param / body for every dispatch path. Four separate tests covered top-level def with direct [], top-level def with local [], instance method, and inherited (multi-level) dispatch. Class names across the four didn't collide, so the merge is straight concatenation with no rename. Local names already differed (names / names1 / names2 / ints / strs).

4 .rb → 1. ~5s saved on Windows test step at the ~1.2s/test rate.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
3a9e73d804ac
Parent
eebfc9c2c66e

test/empty_array_inherited_method.rbdeleted

1-# Issue #84: an empty `[]` literal passed to an inherited method
2-# wasn't promoted to a typed array because the caller-side inference
3-# only updated the receiver class's `@cls_meth_ptypes`, never the
4-# parent class that actually owns the method body. Body-side
5-# promotion in `infer_param_array_type_from_body` then saw the slot
6-# still typed `int`, so the int_array → str_array promotion never
7-# fired and the C code emitted `mrb_int lv_buf` against an
8-# `sp_StrArray *` push.
9-#
10-# Fix walks the inheritance chain in the caller-side inference: when
11-# `cls_find_method_direct(child_ci, mname) < 0`, fall back to the
12-# `find_method_owner` parent and update *its* @cls_meth_ptypes.
13-
14-class Base
15- def add_to(buf)
16- buf.push("hi")
17- end
18-end
19-
20-class Child < Base
21-end
22-
23-names = []
24-Child.new.add_to(names)
25-names.push("more")
26-puts names[0] # hi
27-puts names[1] # more
28-
29-# Two-deep inheritance — Grandchild inherits from Child inherits from
30-# Base, the empty literal flows through to Base#add_to.
31-class Grandchild < Child
32-end
33-
34-names2 = []
35-Grandchild.new.add_to(names2)
36-names2.push("again")
37-puts names2[0] # hi
38-puts names2[1] # again
39-
40-# Inherited method on a class that also defines its own method.
41-# `Mixed#add_to` is its own (different signature), but
42-# `Mixed#also_add` is inherited from Base2. The promotion must hit
43-# Base2's slot, not Mixed's.
44-class Base2
45- def also_add(buf)
46- buf.push("base2")
47- end
48-end
49-
50-class Mixed < Base2
51- def add_to(buf)
52- buf.push(42)
53- end
54-end
55-
56-ints = []
57-Mixed.new.add_to(ints)
58-ints.push(7)
59-puts ints[0] # 42
60-puts ints[1] # 7
61-
62-strs = []
63-Mixed.new.also_add(strs)
64-strs.push("more")
65-puts strs[0] # base2
66-puts strs[1] # more