@@ -47,15 +47,14 @@ def decorate
4747
4848 root . create_path ( constant ) do |job |
4949 method = constant . instance_method ( :perform )
50- constant_name = T . must ( name_of ( constant ) )
51- job_type = generic_job_type ( constant_name )
50+ constant_name = generic_name_of ( constant ) #: as !nil
5251 parameters = compile_method_parameters_to_rbi ( method )
5352 return_type = compile_method_return_type_to_rbi ( method )
5453
5554 job . create_method (
5655 "perform_later" ,
57- parameters : perform_later_parameters ( parameters , job_type ) ,
58- return_type : "T.any(#{ job_type } , FalseClass)" ,
56+ parameters : perform_later_parameters ( parameters , constant_name ) ,
57+ return_type : "T.any(#{ constant_name } , FalseClass)" ,
5958 class_method : true ,
6059 )
6160
@@ -70,32 +69,27 @@ def decorate
7069
7170 private
7271
73- # Resolves the constant name into a valid Sorbet type reference,
74- # applying `T.untyped` for any unfixed generic type variables.
75- #
76- # @example
77- # generic_job_type("StandardJob") # => "StandardJob"
78- # generic_job_type("GenericJob") # => "GenericJob[T.untyped]"
79- #: (String constant_name) -> String
80- def generic_job_type ( constant_name )
81- return constant_name unless T ::Generic === constant
72+ #: (Module[top] constant) -> String?
73+ def generic_name_of ( constant )
74+ type_name = name_of ( constant )
75+ return type_name if !type_name || type_name . end_with? ( "]" )
8276
8377 type_variables = Runtime ::GenericTypeRegistry . lookup_type_variables ( constant )
84- return constant_name unless type_variables
78+ return type_name unless type_variables
8579
86- type_arguments = type_variables . reject ( &:fixed? ) . map { "T.untyped" }
87- return constant_name if type_arguments . empty?
80+ type_variables = type_variables . reject ( &:fixed? )
81+ return type_name if type_variables . empty?
8882
89- "#{ constant_name } [#{ type_arguments . join ( ", " ) } ]"
83+ "#{ type_name } [#{ type_variables . map { "T.untyped" } . join ( ", " ) } ]"
9084 end
9185
92- #: (Array[RBI::TypedParam] parameters, String job_type ) -> Array[RBI::TypedParam]
93- def perform_later_parameters ( parameters , job_type )
86+ #: (Array[RBI::TypedParam] parameters, String constant_name ) -> Array[RBI::TypedParam]
87+ def perform_later_parameters ( parameters , constant_name )
9488 if ::Gem ::Requirement . new ( ">= 7.0" ) . satisfied_by? ( ::ActiveJob . gem_version )
9589 parameters . reject! { |typed_param | RBI ::BlockParam === typed_param . param }
9690 parameters + [ create_block_param (
9791 "block" ,
98- type : "T.nilable(T.proc.params(job: #{ job_type } ).void)" ,
92+ type : "T.nilable(T.proc.params(job: #{ constant_name } ).void)" ,
9993 ) ]
10094 else
10195 parameters
0 commit comments