Skip to content

Commit

Permalink
Fix 3.4 prototype rb failure
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jan 9, 2024
1 parent c7e53d2 commit d760480
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ def literal_to_type(node)
end
when Integer
Types::Literal.new(literal: lit, location: nil)
when String
# For Ruby >=3.3 which generates `LIT` node for string literals inside Hash literal.
# "a" => STR node
# { "a" => nil } => LIT node
Types::Literal.new(literal: lit, location: nil)
else
type_name = TypeName.new(name: lit.class.name.to_sym, namespace: Namespace.root)
Types::ClassInstance.new(name: type_name, args: [], location: nil)
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ def test_literal_to_type
[%{1..2}, %{::Range[::Integer]}],
[%{{}}, %{::Hash[untyped, untyped]}],
[%{{a: nil}}, %{ { a: nil } }],
[%{{"a" => /b/}}, %{ ::Hash[::String, ::Regexp] }],
[%({"a" => /b/}), %({ 'a' => ::Regexp })],
].each do |rb, rbs|
node = RubyVM::AbstractSyntaxTree.parse("_ = #{rb}").children[2]
assert_equal RBS::Parser.parse_type(rbs), parser.literal_to_type(node.children[1])
Expand Down

0 comments on commit d760480

Please sign in to comment.