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
# Issue #84: an empty `[]` literal passed to an inherited method# wasn't promoted to a typed array because the caller-side inference# only updated the receiver class's `@cls_meth_ptypes`, never the# parent class that actually owns the method body. Body-side# promotion in `infer_param_array_type_from_body` then saw the slot# still typed `int`, so the int_array → str_array promotion never# fired and the C code emitted `mrb_int lv_buf` against an# `sp_StrArray *` push.## Fix walks the inheritance chain in the caller-side inference: when# `cls_find_method_direct(child_ci, mname) < 0`, fall back to the# `find_method_owner` parent and update *its* @cls_meth_ptypes.class Base def add_to(buf) buf.push("hi") endendclass Child < Baseendnames = []Child.new.add_to(names)names.push("more")puts names[0] # hiputs names[1] # more# Two-deep inheritance — Grandchild inherits from Child inherits from# Base, the empty literal flows through to Base#add_to.class Grandchild < Childendnames2 = []Grandchild.new.add_to(names2)names2.push("again")puts names2[0] # hiputs names2[1] # again# Inherited method on a class that also defines its own method.# `Mixed#add_to` is its own (different signature), but# `Mixed#also_add` is inherited from Base2. The promotion must hit# Base2's slot, not Mixed's.class Base2 def also_add(buf) buf.push("base2") endendclass Mixed < Base2 def add_to(buf) buf.push(42) endendints = []Mixed.new.add_to(ints)ints.push(7)puts ints[0] # 42puts ints[1] # 7strs = []Mixed.new.also_add(strs)strs.push("more")puts strs[0] # base2puts strs[1] # moretest/empty_array_inherited_method.rb.expecteddeleted
Loading diff…
test/empty_array_param.rbaddedView file
Loading diff…
test/empty_array_param.rb.expectedaddedView file
Loading diff…
test/empty_array_param_class_method.rbdeleted
Loading diff…
test/empty_array_param_class_method.rb.expecteddeleted
Loading diff…
test/empty_array_param_direct.rbdeleted
Loading diff…
test/empty_array_param_direct.rb.expecteddeleted
Loading diff…
test/empty_array_param_local.rbdeleted
Loading diff…
test/empty_array_param_local.rb.expecteddeleted
Loading diff…