From 5fe6c6e4554223a38e3a9bb5f1e43c6374228ea3 Mon Sep 17 00:00:00 2001 From: ksss Date: Wed, 1 Nov 2023 23:09:34 +0900 Subject: [PATCH] Fix error when MASGN Fix https://github.com/ruby/rbs/issues/1330 --- lib/rbs/prototype/rbi.rb | 2 +- test/rbs/rbi_prototype_test.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/rbs/prototype/rbi.rb b/lib/rbs/prototype/rbi.rb index 41f39f6dd..c0a10ffc1 100644 --- a/lib/rbs/prototype/rbi.rb +++ b/lib/rbs/prototype/rbi.rb @@ -246,7 +246,7 @@ def process(node, outer: [], comments:) end end value_node = node.children.last - type = if value_node.type == :CALL && value_node.children[1] == :let + type = if value_node && value_node.type == :CALL && value_node.children[1] == :let type_node = each_arg(value_node.children[2]).to_a[1] type_of type_node, variables: current_module&.type_params || [] else diff --git a/test/rbs/rbi_prototype_test.rb b/test/rbs/rbi_prototype_test.rb index 5b06cb650..8f0107a0a 100644 --- a/test/rbs/rbi_prototype_test.rb +++ b/test/rbs/rbi_prototype_test.rb @@ -546,4 +546,25 @@ class Dir[out X, in Y, Z] end EOF end + + def test_masgn + parser = RBI.new + + parser.parse <<-EOF +class Test + A, B, C = [1, 2, 3] +end + EOF + + assert_write parser.decls, <<-EOF +class Test +end + +Test::A: untyped + +Test::B: untyped + +Test::C: untyped + EOF + end end