Skip to content

Commit bd807e8

Browse files
committed
Fix infinite loop when block has multiple params for sort_by etc
1 parent 491d555 commit bd807e8

3 files changed

Lines changed: 57 additions & 7 deletions

File tree

lib/typeprof/core/ast/call.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ def install0(genv)
139139
end
140140

141141
blk_f_ary_arg = Vertex.new(self)
142-
@changes.add_masgn_box(genv, blk_f_ary_arg, blk_f_args, nil, nil) # TODO: support splat "do |a, *b, c|"
142+
# TODO: support splat "do |a, *b, c|"
143+
blk_f_args.each_with_index do |f_arg, i|
144+
elem_vtx = @changes.add_splat_box(genv, blk_f_ary_arg, i).ret
145+
@changes.add_edge(genv, elem_vtx, f_arg)
146+
end
143147
block = Block.new(self, blk_f_ary_arg, blk_f_args, @block_body.lenv.next_boxes)
144148
blk_ty = Source.new(Type::Proc.new(genv, block))
145149
elsif @block_pass

lib/typeprof/core/env/method.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ def initialize(node, f_ary_arg, f_args, next_boxes)
9494

9595
def accept_args(genv, changes, caller_positionals)
9696
if caller_positionals.size == 1 && @f_args.size >= 2
97-
single_arg = caller_positionals[0]
98-
99-
@f_args.each_with_index do |f_arg, i|
100-
elem_vtx = changes.add_splat_box(genv, single_arg, i).ret
101-
changes.add_edge(genv, elem_vtx, f_arg)
102-
end
97+
changes.add_edge(genv, caller_positionals[0], @f_ary_arg)
10398
else
10499
caller_positionals.zip(@f_args) do |a_arg, f_arg|
105100
changes.add_edge(genv, a_arg, f_arg) if f_arg
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## update
2+
def foo
3+
{ a: 1 }.sort_by do |key_value|
4+
key_value
5+
end
6+
end
7+
8+
def bar
9+
{ a: 1 }.sort_by do |key, value|
10+
key
11+
end
12+
end
13+
14+
def baz
15+
{ a: 1 }.sort_by do |(key, value)|
16+
key
17+
end
18+
end
19+
20+
## assert
21+
class Object
22+
def foo: -> Array[[:a, Integer]]
23+
def bar: -> Array[[:a, Integer]]
24+
def baz: -> Array[[:a, Integer]]
25+
end
26+
27+
## update
28+
def foo
29+
{ 'a' => 1 }.sort_by do |key_value|
30+
key_value
31+
end
32+
end
33+
34+
def bar
35+
{ 'a' => 1 }.sort_by do |key, value|
36+
key
37+
end
38+
end
39+
40+
def baz
41+
{ 'a' => 1 }.sort_by do |(key, value)|
42+
key
43+
end
44+
end
45+
46+
## assert
47+
class Object
48+
def foo: -> Array[[String, Integer]]
49+
def bar: -> Array[[String, Integer]]
50+
def baz: -> Array[[String, Integer]]
51+
end

0 commit comments

Comments
 (0)