diff --git a/lib/rbi/parser.rb b/lib/rbi/parser.rb index bfecfdf8..31cef61d 100644 --- a/lib/rbi/parser.rb +++ b/lib/rbi/parser.rb @@ -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 diff --git a/test/rbi/parser_test.rb b/test/rbi/parser_test.rb index a8f89804..ffdcac5a 100644 --- a/test/rbi/parser_test.rb +++ b/test/rbi/parser_test.rb @@ -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) @@ -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