Skip to content

Commit 16bd31b

Browse files
committed
Merge branch 'type_variable_support' into 2025-07-04
2 parents f2acdf8 + 7ed98b7 commit 16bd31b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/sord/type_converter.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ def self.yard_to_parlour(yard, item, config)
201201
.map { |x| yard_to_parlour(x, item, config) }
202202
if SINGLE_ARG_GENERIC_TYPES.include?(relative_generic_type) && parameters.length > 1
203203
Parlour::Types.const_get(relative_generic_type).new(Parlour::Types::Union.new(parameters))
204+
elsif relative_generic_type == 'generic'
205+
if parameters.length == 1
206+
# used by solargraph to indicate a type variable. Until
207+
# Parlour needs to support separate namespaces, convert to
208+
# the same namespaces as raw types:
209+
parameters.first
210+
else
211+
handle_sord_error(parameters.map(&:describe).join,
212+
"Invalid generic<>, must have exactly one type variable: #{yard.inspect}.", item,
213+
config.replace_errors_with_untyped)
214+
end
204215
elsif relative_generic_type == 'Class'
205216
if parameters.length == 1
206217
Parlour::Types::Class.new(parameters.first)

spec/type_converter_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ def self.path
256256
end
257257
end
258258

259+
context 'with a solargraph-style type variable' do
260+
it 'handles type variables by converting back to RBS-style unified namespace' do
261+
expect(yard_to_parlour_default('generic<Foo>')).to eq Types::Raw.new('Foo')
262+
end
263+
264+
it 'handles generic<> with more than one argument' do
265+
expect(yard_to_parlour_default('generic<F, T>')).to eq Types::Raw.new('SORD_ERROR_FT')
266+
end
267+
end
268+
259269
context 'when given an untyped generic' do
260270
it 'handles Hash correctly' do
261271
expect(yard_to_parlour_default('Hash')).to eq Types::Hash.new(Types::Untyped.new, Types::Untyped.new)

0 commit comments

Comments
 (0)