Skip to content
Merged
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
4 changes: 4 additions & 0 deletions lib/typeprof/core/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ def self.create_node(raw_node, lenv, use_result = true, allow_meta = false)
return AttrReaderMetaNode.new(raw_node, lenv)
when :attr_accessor
return AttrAccessorMetaNode.new(raw_node, lenv)
when :module_function
if raw_node.arguments.nil?
return ModuleFunctionMetaNode.new(raw_node, lenv)
end
end
end
CallNode.new(raw_node, lenv)
Expand Down
6 changes: 6 additions & 0 deletions lib/typeprof/core/ast/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,11 @@ def install0(genv)
Source.new
end
end
class ModuleFunctionMetaNode < Node
def install0(genv)
@lenv.module_function = true
Source.new
end
end
end
end
3 changes: 3 additions & 0 deletions lib/typeprof/core/ast/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def install0(genv)
)

@changes.add_method_def_box(genv, @lenv.cref.cpath, @singleton, @mid, f_args, @body.lenv.return_boxes)
if @lenv.module_function && !@singleton
@changes.add_method_def_box(genv, @lenv.cref.cpath, true, @mid, f_args, @body.lenv.return_boxes)
end

Source.new(Type::Symbol.new(genv, @mid))
end
Expand Down
1 change: 1 addition & 0 deletions lib/typeprof/core/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def initialize(file_context, cref, locals, return_boxes)
end

attr_reader :file_context, :cref, :locals, :return_boxes, :break_vtx, :next_boxes, :strict_const_scope
attr_accessor :module_function

def path = @file_context&.path
def code_range_from_node(node)
Expand Down
16 changes: 16 additions & 0 deletions scenario/misc/module_function.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## update
module Foo
module_function

def bar
42
end
end

Foo.bar

## assert
module Foo
def bar: -> Integer
def self.bar: -> Integer
end
Loading