Skip to content

Commit

Permalink
Merge pull request #394 from Shopify/at-rbs-block-alias
Browse files Browse the repository at this point in the history
Fix RBS translation of non-block type in block position
  • Loading branch information
Morriar authored Jan 15, 2025
2 parents 7a93edf + 4aa8d30 commit 3ac48c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/rbi/rbs_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ def print_method_sig(node, sig)
type_string = "(?) -> untyped"
block_is_nilable = true
when Type::Simple
if block_type.name == "Proc"
type_string = "(?) -> untyped"
end
type_string = "(?) -> untyped"
skip = true if block_type.name == "NilClass"
end

Expand Down
15 changes: 15 additions & 0 deletions test/rbi/rbs_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,21 @@ def d: -> {a: A, "B-B": B}
RBI
end

def test_print_block_type_alias
rbi = parse_rbi(<<~RBI)
BLOCK = T.type_alias { T.proc.void }
sig { params(block: BLOCK) }
def foo(&block); end
RBI

assert_equal(<<~RBI, rbi.rbs_string)
BLOCK: untyped
def foo: { (?) -> untyped } -> void
RBI
end

def test_print_t_structs
rbi = parse_rbi(<<~RBI)
class Foo < T::Struct; end
Expand Down

0 comments on commit 3ac48c6

Please sign in to comment.