Skip to content

Commit

Permalink
Merge pull request #396 from Shopify/at-rbs-method-type-params
Browse files Browse the repository at this point in the history
Do not print type parameters as `TYPE_` when translating to RBS
  • Loading branch information
Morriar authored Jan 15, 2025
2 parents 3ac48c6 + 9216a9d commit 0297249
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rbi/rbs_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def visit_method(node)
sig { params(node: RBI::Method, sig: Sig).void }
def print_method_sig(node, sig)
unless sig.type_params.empty?
print("[#{sig.type_params.map { |t| "TYPE_#{t}" }.join(", ")}] ")
print("[#{sig.type_params.join(", ")}] ")
end

block_param = node.params.find { |param| param.is_a?(BlockParam) }
Expand Down Expand Up @@ -970,7 +970,7 @@ def visit_proc(type)

sig { params(type: Type::TypeParameter).void }
def visit_type_parameter(type)
@string << "TYPE_#{type.name}"
@string << type.name.to_s
end

sig { params(type: Type::Class).void }
Expand Down
3 changes: 1 addition & 2 deletions test/rbi/rbs_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ def test_print_methods_with_signature_with_type_parameters
def foo(a); end
RBI

# To avoid conflict with existing constants, we prefix type parameters with `TYPE_`
assert_equal(<<~RBI, rbi.rbs_string)
def foo: [TYPE_U, TYPE_V] (TYPE_U a) -> TYPE_V
def foo: [U, V] (U a) -> V
RBI
end

Expand Down

0 comments on commit 0297249

Please sign in to comment.