Skip to content

Commit

Permalink
Merge pull request #998 from ksss/args
Browse files Browse the repository at this point in the history
Fix broken args after parsed decls from `RBS::Prototype::RB`
  • Loading branch information
soutaro committed May 19, 2022
2 parents 2b6016f + 7c0660c commit 3b1e64e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ def literal_to_type(node)
Types::ClassInstance.new(name: type_name, args: [], location: nil)
end
when :ZLIST, :ZARRAY
BuiltinNames::Array.instance_type([untyped])
BuiltinNames::Array.instance_type(untyped)
when :LIST, :ARRAY
elem_types = node.children.compact.map { |e| literal_to_type(e) }
t = types_to_union_type(elem_types)
BuiltinNames::Array.instance_type([t])
BuiltinNames::Array.instance_type(t)
when :DOT2, :DOT3
types = node.children.map { |c| literal_to_type(c) }
type = range_element_type(types)
BuiltinNames::Range.instance_type([type])
BuiltinNames::Range.instance_type(type)
when :HASH
list = node.children[0]
if list
Expand Down Expand Up @@ -554,7 +554,7 @@ def literal_to_type(node)
else
key_type = types_to_union_type(key_types)
value_type = types_to_union_type(value_types)
BuiltinNames::Hash.instance_type([key_type, value_type])
BuiltinNames::Hash.instance_type(key_type, value_type)
end
when :CALL
receiver, method_name, * = node.children
Expand Down
17 changes: 17 additions & 0 deletions test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,23 @@ def hello: () -> untyped
RBS
end

def test_literal_to_type
parser = RBS::Prototype::RB.new
[
[%{"abc"}, %{"abc"}],
[%{:abc}, %{:abc}],
[%{[]}, %{::Array[untyped]}],
[%{[true]}, %{::Array[true]}],
[%{1..2}, %{::Range[::Integer]}],
[%{{}}, %{::Hash[untyped, untyped]}],
[%{{a: nil}}, %{ { a: nil } }],
[%{{"a" => /b/}}, %{ ::Hash[::String, ::Regexp] }],
].each do |rb, rbs|
node = RubyVM::AbstractSyntaxTree.parse(rb).children[2]
assert_equal RBS::Parser.parse_type(rbs), parser.literal_to_type(node)
end
end

if RUBY_VERSION >= '2.7'
def test_argument_forwarding
parser = RB.new
Expand Down

0 comments on commit 3b1e64e

Please sign in to comment.