Skip to content

Commit 4260c32

Browse files
alpaca-tcmame
authored andcommitted
Support blank ensure statements.
Fixes a `NoMethodError` that occurred when a begin block included a blank ensure clause. Previously, attempting to handle such a statement resulted in the following error: ``` NoMethodError: undefined method `type' for nil .../typeprof/lib/typeprof/core/ast.rb:24:in `create_node' .../typeprof/lib/typeprof/core/ast/control.rb:369:in `initialize' ``` Related: https://github.com/test-unit/test-unit/blob/68c6c3a/lib/test/unit/testcase.rb#L623
1 parent 93e5f35 commit 4260c32

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/typeprof/core/ast/control.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ def initialize(raw_node, lenv)
366366
end
367367
raw_res = raw_res.subsequent
368368
end
369-
@else_clause = raw_node.else_clause ? AST.create_node(raw_node.else_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
370-
@ensure_clause = raw_node.ensure_clause ? AST.create_node(raw_node.ensure_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
369+
@else_clause = raw_node.else_clause&.statements ? AST.create_node(raw_node.else_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
370+
@ensure_clause = raw_node.ensure_clause&.statements ? AST.create_node(raw_node.ensure_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
371371
end
372372

373373
attr_reader :body, :rescue_conds, :rescue_clauses, :else_clause, :ensure_clause

scenario/control/begin.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ def foo
6060
class Object
6161
def foo: -> (Integer | String | true)
6262
end
63+
64+
## update
65+
def foo
66+
begin
67+
rescue
68+
else
69+
ensure
70+
end
71+
end
72+
73+
## assert
74+
class Object
75+
def foo: -> nil
76+
end

0 commit comments

Comments
 (0)