Skip to content

Commit

Permalink
Handle RBS translation of procs self binding
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 15, 2025
1 parent 06bb85d commit 08b26c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/rbi/rbs_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,12 @@ def visit_proc(type)
end
@string << ") "
end
proc_bind = type.proc_bind
if proc_bind
@string << "[self: "
visit(proc_bind)
@string << "] "
end
@string << "-> "
visit(type.proc_returns)
end
Expand Down
21 changes: 18 additions & 3 deletions test/rbi/rbs_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,29 @@ def e: -> Class[untyped]
RBI
end

def test_print_nilable_proc
def test_print_procs
rbi = parse_rbi(<<~RBI)
sig { params(x: T.nilable(T.proc.void)) }
def foo(x); end
def proc1(x); end
sig { params(x: T.proc.bind(T.untyped).void) }
def proc2(x); end
sig { params(block: T.nilable(T.proc.void)) }
def block1(&block); end
sig { params(block: T.proc.bind(T.untyped).void) }
def block2(&block); end
RBI

assert_equal(<<~RBI, rbi.rbs_string)
def foo: ((^-> void)? x) -> void
def proc1: ((^-> void)? x) -> void
def proc2: (^[self: untyped] -> void x) -> void
def block1: ?{ -> void } -> void
def block2: { [self: untyped] -> void } -> void
RBI
end

Expand Down

0 comments on commit 08b26c2

Please sign in to comment.