Commit 212e85d1

212e85d1645eMerged

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

Description

test: collapse 6 default_arg_* tests into one default_args.rb

Each of default_arg_{ctor,method,inherited,partial,self_call, callee_scope}.rb varied only the dispatch path; the class shapes mostly didn't collide (Foo was reused in self_call and callee_scope for unrelated purposes — renamed here to SelfDefault and CalleeFoo so the test name carries the intent). The basic-method and inherited-dispatch sections now share one Greeter class with a GreeterChild subclass instead of two parallel Greeter / Parent definitions.

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

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

Details

Commit
212e85d1645e
Parent
bd3485cf0752

test/default_arg_callee_scope.rbdeleted

1-# When a callee method's default-arg expression reads from an
2-# instance variable OR calls a same-class method without an
3-# explicit receiver, the inlined expansion at the caller's site
4-# must resolve against the call's *receiver* (and the callee's
5-# class), not the caller's `self`. Naive inlining either fails to
6-# compile or routes through the wrong vtable.
7-
8-# (1) Default reads `@ivar` — must resolve against the recv's
9-# instance, not the caller's.
10-class Wrapper
11- def initialize(seed)
12- @base = seed
13- end
14- def grab(target = @base * 10)
15- target
16- end
17-end
18-
19-class Caller
20- def initialize
21- @w = Wrapper.new(3)
22- end
23- def go
24- @w.grab # default `@base * 10` → 3 * 10 = 30
25- end
26-end
27-
28-puts Caller.new.go # 30
29-
30-# (2) Default calls a same-class bare method — must dispatch to
31-# the *callee's* class, not the caller's. Caller defines its own
32-# method by the same name, but Foo's default should still call
33-# Foo's version.
34-class Foo
35- def target
36- 1
37- end
38- def foo(opt = target)
39- opt
40- end
41-end
42-
43-class Bar
44- def target
45- 2 # different value — must NOT be picked up
46- end
47- def check
48- Foo.new.foo
49- end
50-end
51-
52-puts Bar.new.check # 1 (Foo#target, not Bar#target)