Skip to content

Commit 095ee15

Browse files
committed
Use explicit names for RBI and signature parameters
1 parent c612287 commit 095ee15

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

lib/tapioca/gem/listeners/methods.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public
102102
sanitized_parameters = parameters.each_with_index.map do |(type, name), index|
103103
fallback_arg_name = "_arg#{index}"
104104

105-
name = if name
105+
sig_name = if name
106106
name.to_s
107107
else
108108
# For attr_writer methods, Sorbet signatures have the name
@@ -129,10 +129,11 @@ def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public
129129
# Sanitize param names, except for anonymous splat, keyword splat,
130130
# and block parameters. Ruby reflects those as `:*`, `:**`, and `:&`,
131131
# and Sorbet signatures use the same names to store their types.
132-
is_anonymous_parameter = anonymous_parameter_name?(type, name)
133-
name = fallback_arg_name unless is_anonymous_parameter || valid_parameter_name?(name)
132+
is_anonymous_parameter = anonymous_parameter_name?(type, sig_name)
133+
sig_name = fallback_arg_name unless is_anonymous_parameter || valid_parameter_name?(sig_name)
134+
param_name = is_anonymous_parameter ? nil : sig_name
134135

135-
[type, name, is_anonymous_parameter]
136+
[type, param_name, sig_name]
136137
end
137138

138139
rbi_method = RBI::Method.new(
@@ -141,26 +142,26 @@ def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public
141142
visibility: visibility,
142143
)
143144

144-
sanitized_parameters.each do |type, name, is_anonymous_parameter|
145+
sanitized_parameters.each do |type, param_name, _sig_name|
145146
case type
146147
when :req
147-
rbi_method << RBI::ReqParam.new(name)
148+
rbi_method << RBI::ReqParam.new(param_name)
148149
when :opt
149-
rbi_method << RBI::OptParam.new(name, "T.unsafe(nil)")
150+
rbi_method << RBI::OptParam.new(param_name, "T.unsafe(nil)")
150151
when :rest
151-
rbi_method << RBI::RestParam.new(is_anonymous_parameter ? nil : name)
152+
rbi_method << RBI::RestParam.new(param_name)
152153
when :keyreq
153-
rbi_method << RBI::KwParam.new(name)
154+
rbi_method << RBI::KwParam.new(param_name)
154155
when :key
155-
rbi_method << RBI::KwOptParam.new(name, "T.unsafe(nil)")
156+
rbi_method << RBI::KwOptParam.new(param_name, "T.unsafe(nil)")
156157
when :keyrest
157-
rbi_method << RBI::KwRestParam.new(is_anonymous_parameter ? nil : name)
158+
rbi_method << RBI::KwRestParam.new(param_name)
158159
when :block
159-
rbi_method << RBI::BlockParam.new(is_anonymous_parameter ? nil : name)
160+
rbi_method << RBI::BlockParam.new(param_name)
160161
end
161162
end
162163

163-
parameters_for_signature = sanitized_parameters.map { |type, name, _is_anonymous_parameter| [type, name] }
164+
parameters_for_signature = sanitized_parameters.map { |type, _param_name, sig_name| [type, sig_name] }
164165
@pipeline.push_method(symbol_name, constant, method, rbi_method, signature, parameters_for_signature)
165166
tree << rbi_method
166167
end

0 commit comments

Comments
 (0)