Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/typeprof/core/ast/const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,30 @@ def install0(genv)
@cpath.install(genv) if @cpath
val = @rhs.install(genv)
if @static_cpath
@changes.add_edge(genv, val, @static_ret.vtx)
if detect_class_new?(@rhs)
# Create a module entity for the dynamically created class
mod = genv.resolve_cpath(@static_cpath)

# Create singleton type for the new class
singleton_ty = Type::Singleton.new(genv, mod)
vtx = Source.new(singleton_ty)
@changes.add_edge(genv, vtx, @static_ret.vtx)
else
@changes.add_edge(genv, val, @static_ret.vtx)
end
end
val
end

private

def detect_class_new?(node)
node.is_a?(CallBaseNode) &&
node.mid == :new &&
node.recv.is_a?(ConstantReadNode) &&
node.recv.cname == :Class &&
node.recv.cbase.nil?
end
end
end
end
15 changes: 15 additions & 0 deletions scenario/control/rescue-assign-with-class-new.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## update: my_error.rb
MyError = Class.new(StandardError)

## update: test.rb
class C
def foo
rescue MyError => e
raise ArgumentError, e.message
end
end

## assert: test.rb
class C
def foo: -> nil
end