Skip to content

Commit c15b444

Browse files
mamepvcresin
andauthored
Fix crash in break in loop (#365)
This change avoids multi-edges by creating an intermediate vertex between an `break` argument and its iterator's result. Fixes #356 Co-authored-by: pvcresin <toriyama@sansan.com>
1 parent 753de9b commit c15b444

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GIT
1010
PATH
1111
remote: .
1212
specs:
13-
typeprof (0.31.0)
13+
typeprof (0.31.1)
1414
prism (>= 1.4.0)
1515
rbs (>= 3.6.0)
1616

lib/typeprof/core/ast/control.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def subnodes = { arg: }
203203

204204
def install0(genv)
205205
arg = @arg.install(genv)
206-
@changes.add_edge(genv, arg, @lenv.get_break_vtx)
206+
@changes.add_edge(genv, arg.new_vertex(genv, self), @lenv.get_break_vtx)
207207
Source.new()
208208
end
209209
end

scenario/control/break2.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## update
2+
def foo
3+
count = 0
4+
loop do
5+
count += 1
6+
break count if count == 3
7+
end
8+
end
9+
10+
## assert
11+
class Object
12+
def foo: -> Integer
13+
end
14+
15+
## update
16+
def foo
17+
count = 0
18+
loop do
19+
count += 1
20+
begin
21+
break count if count == 3
22+
rescue
23+
break count
24+
end
25+
end
26+
end
27+
28+
## assert
29+
class Object
30+
def foo: -> Integer
31+
end
32+
33+
## update
34+
def foo
35+
count = 0
36+
loop do
37+
count += 1
38+
begin
39+
break count if count == 3
40+
rescue
41+
break 'str'
42+
end
43+
end
44+
end
45+
46+
## assert
47+
class Object
48+
def foo: -> (Integer | String)
49+
end
50+
51+
## update
52+
def foo
53+
count = 0
54+
loop do
55+
count += 1
56+
begin
57+
# break count if count == 3
58+
rescue
59+
break 'str'
60+
end
61+
end
62+
end
63+
64+
## assert
65+
class Object
66+
def foo: -> String
67+
end

0 commit comments

Comments
 (0)