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 head test fails #1719

Merged
merged 4 commits into from
Jan 12, 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GEM
addressable (>= 2.8)
language_server-protocol (3.17.0.3)
marcel (1.0.2)
minitest (5.20.0)
minitest (5.21.1)
net-protocol (0.2.2)
timeout
net-smtp (0.4.0.1)
Expand Down
6 changes: 3 additions & 3 deletions bin/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
require "set"

IS_LATEST_RUBY = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
Gem::Version.new('3.2.0') <= ruby_version && ruby_version < Gem::Version.new('3.3.0')
Gem::Version.new('3.3.0') <= ruby_version && ruby_version < Gem::Version.new('3.4.0')
end

unless IS_LATEST_RUBY
unless ENV["CI"]
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.2 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.3 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
end
end

KNOWN_FAILS = %w(dbm).map do |lib|
KNOWN_FAILS = %w(dbm mutex_m).map do |lib|
/cannot load such file -- #{lib}/
end

Expand Down
13 changes: 12 additions & 1 deletion lib/rbs/prototype/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def any_node?(node, nodes: [], &block)
def keyword_hash?(node)
if node && node.type == :HASH
node.children[0].children.compact.each_slice(2).all? {|key, _|
key.type == :LIT && key.children[0].is_a?(Symbol)
symbol_literal_node?(key)
}
else
false
Expand All @@ -122,6 +122,17 @@ def args_from_node(args_node)
args_node&.children || [0, nil, nil, nil, 0, nil, nil, nil, nil, nil]
end

def symbol_literal_node?(node)
case node.type
when :LIT
if node.children[0].is_a?(Symbol)
node.children[0]
end
when :SYM
node.children[0]
end
end

def untyped
@untyped ||= Types::Bases::Any.new(location: nil)
end
Expand Down
11 changes: 11 additions & 0 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ def const_to_name(node, context:)

def literal_to_symbol(node)
case node.type
when :SYM
node.children[0]
when :LIT
node.children[0] if node.children[0].is_a?(Symbol)
when :STR
Expand Down Expand Up @@ -574,6 +576,13 @@ def literal_to_type(node)
end
when :DSTR, :XSTR
BuiltinNames::String.instance_type
when :SYM
lit = node.children[0]
if lit.to_s.ascii_only?
Types::Literal.new(literal: lit, location: nil)
else
BuiltinNames::Symbol.instance_type
end
when :DSYM
BuiltinNames::Symbol.instance_type
when :DREGX
Expand Down Expand Up @@ -718,6 +727,8 @@ def param_type(node, default: Types::Bases::Any.new(location: nil))
else
default
end
when :SYM
BuiltinNames::Symbol.instance_type
when :STR, :DSTR
BuiltinNames::String.instance_type
when :NIL
Expand Down
16 changes: 9 additions & 7 deletions lib/rbs/prototype/rbi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module RBS
module Prototype
class RBI
include Helpers

attr_reader :decls
attr_reader :modules
attr_reader :last_sig
Expand Down Expand Up @@ -218,11 +220,11 @@ def process(node, outer: [], comments:)
if (send = node.children.last) && send.type == :FCALL && send.children[0] == :type_member
unless each_arg(send.children[1]).any? {|node|
node.type == :HASH &&
each_arg(node.children[0]).each_slice(2).any? {|a, _| a.type == :LIT && a.children[0] == :fixed }
each_arg(node.children[0]).each_slice(2).any? {|a, _| symbol_literal_node?(a) == :fixed }
}
# @type var variance: AST::TypeParam::variance?
if (a0 = each_arg(send.children[1]).to_a[0]) && a0.type == :LIT
variance = case a0.children[0]
if (a0 = each_arg(send.children[1]).to_a[0]) && (v = symbol_literal_node?(a0))
variance = case v
when :out
:covariant
when :in
Expand Down Expand Up @@ -321,8 +323,8 @@ def method_type(args_node, type_node, variables:, overloads:)
type_params = []

each_arg args do |node|
if node.type == :LIT
type_params << node.children[0]
if name = symbol_literal_node?(node)
type_params << name
end
end

Expand Down Expand Up @@ -613,8 +615,8 @@ def node_to_hash(node)
each_arg(node.children[0]).each_slice(2) do |var, type|
var or raise

if var.type == :LIT && type
hash[var.children[0]] = type
if (name = symbol_literal_node?(var)) && type
hash[name] = type
end
end

Expand Down
4 changes: 4 additions & 0 deletions sig/prototype/helpers.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module RBS

def keyword_hash?: (node) -> bool

# Returns a symbol if the node is a symbol literal node
#
def symbol_literal_node?: (node) -> Symbol?

def args_from_node: (node?) -> Array[untyped]

def untyped: () -> Types::Bases::Any
Expand Down
2 changes: 2 additions & 0 deletions sig/prototype/rbi.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module RBS
module Prototype
class RBI
include Helpers

attr_reader decls: Array[AST::Declarations::t]

type module_decl = AST::Declarations::Class | AST::Declarations::Module
Expand Down