From 4379baa95af32e7351473831e0d369ba689e4593 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 3 Apr 2026 19:57:13 +0900 Subject: [PATCH] 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) --- lib/typeprof/core/graph/filter.rb | 3 +++ scenario/flow/begin_rescue_var.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 scenario/flow/begin_rescue_var.rb diff --git a/lib/typeprof/core/graph/filter.rb b/lib/typeprof/core/graph/filter.rb index a41bd53aa..06ada7aaf 100644 --- a/lib/typeprof/core/graph/filter.rb +++ b/lib/typeprof/core/graph/filter.rb @@ -114,6 +114,9 @@ def on_type_added(genv, src_var, added_types) if src_var == @base_vtx if @base_vtx.types.size == 1 && @base_vtx.types.include?(genv.bot_type) @next_vtx.on_type_removed(genv, self, @types.keys & @next_vtx.types.keys) # XXX: smoke/control/bot2.rb + else + # base_vtx is no longer bot-only; restore any previously suppressed types + @next_vtx.on_type_added(genv, self, @types.keys - @next_vtx.types.keys) end else added_types.each do |ty| diff --git a/scenario/flow/begin_rescue_var.rb b/scenario/flow/begin_rescue_var.rb new file mode 100644 index 000000000..70db7ccc8 --- /dev/null +++ b/scenario/flow/begin_rescue_var.rb @@ -0,0 +1,19 @@ +## update +def test(cond, val) + if cond + begin + val = val.to_i + rescue + raise "bad" + end + end + val +end + +test(true, "42") +test(false, "hello") + +## assert +class Object + def test: (bool, String) -> (Integer | String) +end