Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of type members and templates #339

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading