Skip to content

Commit

Permalink
Support undef statement (as nop)
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Jul 23, 2024
1 parent a4bc34a commit 9055651
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/typeprof/core/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def self.create_node(raw_node, lenv, use_result = true)
when :singleton_class_node then SingletonClassNode.new(raw_node, lenv, use_result)
when :def_node then DefNode.new(raw_node, lenv, use_result)
when :alias_method_node then AliasNode.new(raw_node, lenv)
when :undef_node then UndefNode.new(raw_node, lenv)

# control
when :and_node then AndNode.new(raw_node, lenv)
Expand Down
20 changes: 20 additions & 0 deletions lib/typeprof/core/ast/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,25 @@ def install0(genv)
end
end
end

class UndefNode < Node
def initialize(raw_node, lenv)
super(raw_node, lenv)
@names = raw_node.names.map do |raw_name|
AST.create_node(raw_name, lenv)
end
end

attr_reader :names

def subnodes = { names: }

def install0(genv)
@names.each do |name|
name.install(genv)
end
Source.new(genv.nil_type)
end
end
end
end
16 changes: 16 additions & 0 deletions scenario/method/undef.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## update
class Foo
def foo
42
end

# Currently, TypeProf just ignores undef statements
undef foo
undef :foo, :bar
undef :"foo#{ 42 }"
end

## assert
class Foo
def foo: -> Integer
end

0 comments on commit 9055651

Please sign in to comment.