Skip to content

Commit

Permalink
Fix printing of signatures with final modifier in block
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jul 2, 2024
1 parent f7a13b7 commit 2499eb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rbi/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ def print_sig_as_line(node)
def print_sig_as_block(node)
modifiers = sig_modifiers(node)

printl("sig do")
printt("sig")
print("(:final)") if node.is_final
printn(" do")
indent
if modifiers.any?
printl(T.must(modifiers.first))
Expand Down
14 changes: 14 additions & 0 deletions test/rbi/printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1138,5 +1138,19 @@ def test_print_sigs_locations
def m1; end
RBI
end

def test_print_sigs_with_final
sig = Sig.new(is_final: true, return_type: "Integer")

assert_equal(<<~RBI, sig.string)
sig(:final) { returns(Integer) }
RBI

assert_equal(<<~RBI, sig.string(max_line_length: 10))
sig(:final) do
returns(Integer)
end
RBI
end
end
end

0 comments on commit 2499eb9

Please sign in to comment.