Skip to content

Commit 774ec0b

Browse files
alpaca-tcmame
authored andcommitted
Support for implicit rest arguments in array patterns for repl_type_completor
Fix the following error: ``` Error: test: scenario/patterns/array_pat.rb(ScenarioCompiler::ScenarioTest): NoMethodError: undefined method 'expression' for an instance of Prism::ImplicitRestNode lib/typeprof/core/ast/pattern.rb:8:in 'TypeProf::Core::AST::ArrayPatternNode#initialize' ```
1 parent 4da7092 commit 774ec0b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/typeprof/core/ast/pattern.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ def initialize(raw_node, lenv)
55
super(raw_node, lenv)
66
@requireds = raw_node.requireds.map {|raw_pat| AST.create_pattern_node(raw_pat, lenv) }
77
@rest = !!raw_node.rest
8-
@rest_pattern = raw_node.rest && raw_node.rest.expression ? AST.create_pattern_node(raw_node.rest.expression, lenv) : nil
8+
@rest_pattern = case raw_node.rest
9+
when Prism::SplatNode
10+
AST.create_pattern_node(raw_node.rest.expression, lenv) if raw_node.rest.expression
11+
when Prism::ImplicitRestNode, nil
12+
nil
13+
else
14+
raise
15+
end
16+
917
@posts = raw_node.posts.map {|raw_pat| AST.create_pattern_node(raw_pat, lenv) }
1018
end
1119

scenario/patterns/array_pat.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def check(x)
1212
:baz # TODO: this should be excluded
1313
in MyArray[1, 2, 3]
1414
:qux
15+
in [1,]
16+
:waldo
1517
else
1618
:zzz
1719
end
@@ -23,5 +25,5 @@ def check(x)
2325
class MyArray
2426
end
2527
class Object
26-
def check: (Array[Integer]) -> (:bar | :baz | :foo | :qux | :zzz)
28+
def check: (Array[Integer]) -> (:bar | :baz | :foo | :qux | :waldo | :zzz)
2729
end

0 commit comments

Comments
 (0)