Skip to content

Commit

Permalink
Tentative support of post_execution_node
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Aug 7, 2024
1 parent e3729ad commit 1f4b9e9
Show file tree
Hide file tree
Showing 4 changed files with 48 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 @@ -216,6 +216,7 @@ def self.create_node(raw_node, lenv, use_result = true)
when :splat_node then SplatNode.new(raw_node, lenv)
when :for_node then ForNode.new(raw_node, lenv)
when :alias_global_variable_node then AliasGlobalVariableNode.new(raw_node, lenv)
when :post_execution_node then PostExecutionNode.new(raw_node, lenv)

# call
when :super_node then SuperNode.new(raw_node, lenv)
Expand Down
16 changes: 16 additions & 0 deletions lib/typeprof/core/ast/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ def install0(genv)
end
end

class PostExecutionNode < Node
def initialize(raw_node, lenv)
super(raw_node, lenv)
@body = raw_node.statements ? AST.create_node(raw_node.statements, lenv) : DummyNilNode.new(TypeProf::CodeRange.new(code_range.last, code_range.last), lenv)
end

attr_reader :body

def subnodes = { body: }

def install0(genv)
@body.install(genv)
Source.new(genv.nil_type)
end
end

class ClassVariableWriteNode < Node
def initialize(raw_node, rhs, lenv)
super(raw_node, lenv)
Expand Down
15 changes: 15 additions & 0 deletions scenario/known-issues/post-exec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## update
def check(x)
end

def foo
x = 1
END { check(x) }
x = "str"
end

## assert
class Object
def check: (String) -> nil
def foo: -> nil
end
16 changes: 16 additions & 0 deletions scenario/misc/post-exec-tmp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## update
def check(x)
end

def foo
x = 1
END { check(x) } # TODO: This shoud pass String, but it is not implemented yet
# See known-issues/post-exec.rb
x = "str"
end

## assert
class Object
def check: (Integer) -> nil
def foo: -> String
end

0 comments on commit 1f4b9e9

Please sign in to comment.