Skip to content

Commit b4c2db3

Browse files
mamesinsokuclaude
committed
Fix crash when rescuing non-class constants
Previously, TypeProf would crash when encountering `rescue X => e` if `X` was a non-class constant (e.g., `X = 1`). This commit fixes the issue by handling cases where the rescued object is not a singleton type, preventing the unhandled exception during type inference. Fixes #351 Co-Authored-By: Takumi Shotoku <[email protected]> Co-Authored-By: Claude <[email protected]>
1 parent 5ae799f commit b4c2db3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/typeprof/core/graph/box.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def initialize(node, genv, singleton_ty_vtx)
10991099
def run0(genv, changes)
11001100
instance_tys = []
11011101
@singleton_ty_vtx.each_type do |ty|
1102-
instance_tys << ty.get_instance_type(genv)
1102+
instance_tys << ty.get_instance_type(genv) if ty.is_a?(Type::Singleton)
11031103
end
11041104
source_vtx = Source.new(*instance_tys)
11051105
changes.add_edge(genv, source_vtx, @ret)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## update: my_error.rb
2+
MyError = Class.new(StandardError)
3+
4+
## update: test.rb
5+
class C
6+
def foo
7+
rescue MyError => e
8+
raise ArgumentError, e.message
9+
end
10+
end
11+
12+
## assert: test.rb
13+
class C
14+
def foo: -> nil
15+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## update
2+
NonException = :foo
3+
4+
def foo(n)
5+
1
6+
rescue NonException => e
7+
e
8+
end
9+
10+
## diagnostics
11+
12+
## assert
13+
NonException: :foo
14+
class Object
15+
def foo: (untyped) -> Integer
16+
end

0 commit comments

Comments
 (0)