AaronC81 / sord

Convert YARD docs to Sorbet RBI and Ruby 3/Steep RBS files
https://sord.aaronc.cc
MIT License
299 stars 18 forks source link

Support Class with multiple parameters as union type of class types #173

Open tomoasleep opened 1 year ago

tomoasleep commented 1 year ago

For now, when sord sees the type Class<String, Integer>, sord crashes with the following error.

     Failure/Error: Parlour::Types.const_get(relative_generic_type).new(*parameters)

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     # ~/.anyenv/envs/rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.10950/lib/types/private/methods/call_validation_2_7.rb:1000:in `block in create_validator_procedure_medium1'
     # ~/.anyenv/envs/rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.10950/lib/types/private/abstract/declare.rb:38:in `new'
     # ~/.anyenv/envs/rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.10950/lib/types/private/abstract/declare.rb:38:in `block in declare_abstract'
     # ./lib/sord/type_converter.rb:212:in `yard_to_parlour'

(The error means Parlour::Types::Class.new only accepts 1 parameter.)

With this PR, sord avoids the error and considers the type as union of class types.