Skip to content

Commit

Permalink
Fix RBS translation of non-block type in block position
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Jan 14, 2025
1 parent e9c6406 commit 64312e5
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 @@ -388,9 +388,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 @@ -530,6 +530,21 @@ def foo: -> instance
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 64312e5

Please sign in to comment.