Skip to content

Commit 00c8f82

Browse files
committed
Fix NoMethodError in CallBaseNode#modified_vars for anonymous rest
Since ff8a516, anonymous rest arguments (bare `*`) are represented as `nil` placeholders in `@positional_args` instead of `DummyNilNode`. However, `CallBaseNode#modified_vars` iterates the positional args array without skipping nil, raising NoMethodError when a call with anonymous rest forwarding appears inside a branch (e.g. `if cond; bar(*); end`) whose `modified_vars` is walked from `BranchNode#install0`. Use safe navigation so nil placeholders are skipped, matching how `each_subnode` already guards against nil subnodes. Add a regression case to scenario/args/anonymous_rest.rb.
1 parent 283b5d9 commit 00c8f82

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/typeprof/core/ast/call.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def modified_vars(tbl, vars)
247247
subnode.modified_vars(tbl, vars)
248248
end
249249
else
250-
subnode.each {|n| n.modified_vars(tbl, vars) }
250+
subnode.each {|n| n&.modified_vars(tbl, vars) }
251251
end
252252
end
253253
end

scenario/args/anonymous_rest.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ def bar(*)
77
nil
88
end
99

10+
def foo_in_if(*)
11+
if true
12+
bar(*)
13+
end
14+
end
15+
1016
bar(1, "foo")
1117

1218
## assert
1319
class Object
1420
def foo: (*untyped) -> nil
1521
def bar: (*Integer | String) -> nil
22+
def foo_in_if: (*untyped) -> nil
1623
end

0 commit comments

Comments
 (0)