Skip to content
Draft
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
11 changes: 11 additions & 0 deletions lib/sord/type_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ def self.yard_to_parlour(yard, item, config)
.map { |x| yard_to_parlour(x, item, config) }
if SINGLE_ARG_GENERIC_TYPES.include?(relative_generic_type) && parameters.length > 1
Parlour::Types.const_get(relative_generic_type).new(Parlour::Types::Union.new(parameters))
elsif relative_generic_type == 'generic'
if parameters.length == 1
# used by solargraph to indicate a type variable. Until
# Parlour needs to support separate namespaces, convert to
# the same namespaces as raw types:
parameters.first
else
handle_sord_error(parameters.map(&:describe).join,
"Invalid generic<>, must have exactly one type variable: #{yard.inspect}.", item,
config.replace_errors_with_untyped)
end
elsif relative_generic_type == 'Class'
if parameters.length == 1
Parlour::Types::Class.new(parameters.first)
Expand Down
12 changes: 11 additions & 1 deletion spec/type_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ def self.path
end
end

context 'with a solargraph-style type variable' do
it 'handles type variables by converting back to RBS-style unified namespace' do
expect(yard_to_parlour_default('generic<Foo>')).to eq Types::Raw.new('Foo')
end

it 'handles generic<> with more than one argument' do
expect(yard_to_parlour_default('generic<F, T>')).to eq Types::Raw.new('SORD_ERROR_FT')
end
end

context 'when given an untyped generic' do
it 'handles Hash correctly' do
expect(yard_to_parlour_default('Hash')).to eq Types::Hash.new(Types::Untyped.new, Types::Untyped.new)
Expand Down Expand Up @@ -339,7 +349,7 @@ def self.path
Sord::TypeConverter::Configuration.new(
output_language: :rbs,
replace_errors_with_untyped: false,
replace_unresolved_with_untyped: false,
replace_unresolved_with_untyped: false,
)
end

Expand Down