Skip to content

Commit

Permalink
Fix parsing of type members and templates
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Aug 6, 2024
1 parent 34c5f7f commit 53243b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/rbi/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,7 @@ def set_root_tree_loc

sig { params(node: T.nilable(Prism::Node)).returns(T::Boolean) }
def type_variable_definition?(node)
return false unless node.is_a?(Prism::CallNode)
return false unless node.block

node.message == "type_member" || node.message == "type_template"
node.is_a?(Prism::CallNode) && (node.message == "type_member" || node.message == "type_template")
end
end

Expand Down
10 changes: 8 additions & 2 deletions test/rbi/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_parse_sorbet_type_members_and_templates
class Foo
A = type_member
B = type_member(:in)
C = type_member(:tree)
C = type_member(:out) {}
D = type_member(lower: A)
E = type_member(upper: A)
F = type_member(:in, fixed: A)
Expand All @@ -329,7 +329,13 @@ class Foo
end
RBI

tree = parse_rbi(rbi)
tree = Parser.parse_string(rbi)

# Make sure the type members and templates are not parsed as constants
cls = T.must(tree.nodes.grep(Class).first)
assert_equal(0, cls.nodes.grep(Const).size)
assert_equal(9, cls.nodes.grep(TypeMember).size)

assert_equal(rbi, tree.string)
end

Expand Down

0 comments on commit 53243b4

Please sign in to comment.