Skip to content

Commit 885d081

Browse files
mameclaude
andcommitted
Fix BotFilter to restore types when base exits bot-only state
When a BotFilter's base_vtx transitions from bot-only to having non-bot types, previously suppressed variable types were not restored. This caused variables assigned inside begin/rescue blocks to lose their types when the rescue clause contained raise (bot). The fix adds type restoration in on_type_added when the base_vtx is no longer bot-only. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b9c3cd3 commit 885d081

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/typeprof/core/graph/filter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def on_type_added(genv, src_var, added_types)
114114
if src_var == @base_vtx
115115
if @base_vtx.types.size == 1 && @base_vtx.types.include?(genv.bot_type)
116116
@next_vtx.on_type_removed(genv, self, @types.keys & @next_vtx.types.keys) # XXX: smoke/control/bot2.rb
117+
else
118+
# base_vtx is no longer bot-only; restore any previously suppressed types
119+
@next_vtx.on_type_added(genv, self, @types.keys - @next_vtx.types.keys)
117120
end
118121
else
119122
added_types.each do |ty|

scenario/flow/begin_rescue_var.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## update
2+
def test(cond, val)
3+
if cond
4+
begin
5+
val = val.to_i
6+
rescue
7+
raise "bad"
8+
end
9+
end
10+
val
11+
end
12+
13+
test(true, "42")
14+
test(false, "hello")
15+
16+
## assert
17+
class Object
18+
def test: (bool, String) -> (Integer | String)
19+
end

0 commit comments

Comments
 (0)