Skip to content

Commit ba9f9f6

Browse files
ahogappaclaude
authored andcommitted
Fix crash on empty parentheses () in AST conversion
`AST.create_node` unwraps `:parentheses_node` by assigning `raw_node = raw_node.body`, but for `()` the body is nil, causing a NoMethodError on the subsequent `raw_node.type` dispatch. Return `DummyNilNode` when the body is nil, following the existing convention for empty syntactic slots that evaluate to nil. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 94ffade commit ba9f9f6

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/typeprof/core/ast.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def self.create_node(raw_node, lenv, use_result = true, allow_meta = false)
6161
while true
6262
case raw_node.type
6363
when :parentheses_node
64+
return DummyNilNode.new(lenv.code_range_from_node(raw_node), lenv) if raw_node.body.nil?
6465
raw_node = raw_node.body
6566
when :implicit_node
6667
raw_node = raw_node.value

scenario/misc/parens.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## update
2+
def grouping
3+
(1 + 2)
4+
end
5+
6+
def nested
7+
((3))
8+
end
9+
10+
def empty
11+
()
12+
end
13+
14+
def with_default(x = ())
15+
x
16+
end
17+
18+
grouping
19+
nested
20+
empty
21+
with_default
22+
with_default(1)
23+
24+
## assert
25+
class Object
26+
def grouping: -> Integer
27+
def nested: -> Integer
28+
def empty: -> nil
29+
def with_default: (?Integer?) -> Integer?
30+
end

0 commit comments

Comments
 (0)