1+ # regression test for popping before side exit
2+ assert_equal "ok" , %q{
3+ def foo(a, *) = a
4+
5+ def call(args, &)
6+ foo(1) # spill at where the block arg will be
7+ foo(*args, &)
8+ end
9+
10+ call([1, 2])
11+
12+ begin
13+ call([])
14+ rescue ArgumentError
15+ :ok
16+ end
17+ }
18+
19+ # regression test for send processing before side exit
20+ assert_equal "ok" , %q{
21+ def foo(a, *) = :foo
22+
23+ def call(args)
24+ send(:foo, *args)
25+ end
26+
27+ call([1, 2])
28+
29+ begin
30+ call([])
31+ rescue ArgumentError
32+ :ok
33+ end
34+ }
35+
36+ # test discarding extra yield arguments
37+ assert_equal "2210150001501015" , %q{
38+ def splat_kw(ary) = yield *ary, a: 1
39+
40+ def splat(ary) = yield *ary
41+
42+ def kw = yield 1, 2, a: 0
43+
44+ def simple = yield 0, 1
45+
46+ def calls
47+ [
48+ splat([1, 1, 2]) { |x, y| x + y },
49+ splat([1, 1, 2]) { |y, opt = raise| opt + y},
50+ splat_kw([0, 1]) { |a:| a },
51+ kw { |a:| a },
52+ kw { |a| a },
53+ simple { 5.itself },
54+ simple { |a| a },
55+ simple { |opt = raise| opt },
56+ simple { |*rest| rest },
57+ simple { |opt_kw: 5| opt_kw },
58+ # autosplat ineractions
59+ [0, 1, 2].yield_self { |a, b| [a, b] },
60+ [0, 1, 2].yield_self { |a, opt = raise| [a, opt] },
61+ [1].yield_self { |a, opt = 4| a + opt },
62+ ]
63+ end
64+
65+ calls.join
66+ }
67+
68+ # test autosplat with empty splat
69+ assert_equal "ok" , %q{
70+ def m(pos, splat) = yield pos, *splat
71+
72+ m([:ok], []) {|v0,| v0 }
73+ }
74+
175# regression test for send stack shifting
276assert_normal_exit %q{
377 def foo(a, b)
@@ -11,6 +85,13 @@ def call_foo
1185 call_foo
1286}
1387
88+ # regression test for keyword splat with yield
89+ assert_equal 'nil' , %q{
90+ def splat_kw(kwargs) = yield(**kwargs)
91+
92+ splat_kw({}) { _1 }.inspect
93+ } unless rjit_enabled? # Not yet working on RJIT
94+
1495# regression test for arity check with splat
1596assert_equal '[:ae, :ae]' , %q{
1697 def req_one(a_, b_ = 1) = raise
@@ -4342,3 +4423,34 @@ def entry
43424423
43434424 entry
43444425}
4426+
4427+ # Integer succ and overflow
4428+ assert_equal '[2, 4611686018427387904]' , %q{
4429+ [1.succ, 4611686018427387903.succ]
4430+ }
4431+
4432+ # Integer right shift
4433+ assert_equal '[0, 1, -4]' , %q{
4434+ [0 >> 1, 2 >> 1, -7 >> 1]
4435+ }
4436+
4437+ assert_equal '[nil, "yield"]' , %q{
4438+ def defined_yield = defined?(yield)
4439+ [defined_yield, defined_yield {}]
4440+ }
4441+
4442+ # splat with ruby2_keywords into rest parameter
4443+ assert_equal '[[{:a=>1}], {}]' , %q{
4444+ ruby2_keywords def foo(*args) = args
4445+
4446+ def bar(*args, **kw) = [args, kw]
4447+
4448+ def pass_bar(*args) = bar(*args)
4449+
4450+ def body
4451+ args = foo(a: 1)
4452+ pass_bar(*args)
4453+ end
4454+
4455+ body
4456+ }
0 commit comments