File tree Expand file tree Collapse file tree 3 files changed +782
-1
lines changed
spec/tapioca/dsl/compilers Expand file tree Collapse file tree 3 files changed +782
-1
lines changed Original file line number Diff line number Diff line change @@ -278,7 +278,16 @@ def common_relation_methods_module
278278
279279 sig { returns ( String ) }
280280 def constant_name
281- @constant_name ||= T . let ( T . must ( qualified_name_of ( constant ) ) , T . nilable ( String ) )
281+ @constant_name ||= T . let ( constant_name_of ( constant ) , T . nilable ( String ) )
282+ end
283+
284+ sig { params ( constant : ConstantType ) . returns ( String ) }
285+ def constant_name_of ( constant )
286+ if T ::Generic === constant
287+ generic_name_of ( constant )
288+ else
289+ T . must ( qualified_name_of ( constant ) )
290+ end
282291 end
283292
284293 sig { params ( method_name : Symbol ) . returns ( T ::Boolean ) }
Original file line number Diff line number Diff line change @@ -138,5 +138,33 @@ def valid_parameter_name?(name)
138138 rescue SyntaxError
139139 false
140140 end
141+
142+ sig { params ( constant : T . all ( Module , T ::Generic ) ) . returns ( String ) }
143+ def generic_name_of ( constant )
144+ type_name = T . must ( qualified_name_of ( constant ) )
145+ return type_name if type_name =~ /\[ .*\] $/
146+
147+ type_variables = Runtime ::GenericTypeRegistry . lookup_type_variables ( constant )
148+ return type_name unless type_variables
149+
150+ type_variables = type_variables . reject ( &:fixed? )
151+ return type_name if type_variables . empty?
152+
153+ type_variable_names = type_variables . map { "T.untyped" } . join ( ", " )
154+
155+ "#{ type_name } [#{ type_variable_names } ]"
156+ end
157+
158+ sig { params ( constant : Module ) . returns ( T . nilable ( String ) ) }
159+ def qualified_name_of ( constant )
160+ name = name_of ( constant )
161+ return if name . nil?
162+
163+ if name . start_with? ( "::" )
164+ name
165+ else
166+ "::#{ name } "
167+ end
168+ end
141169 end
142170end
You can’t perform that action at this time.
0 commit comments