Skip to content

Commit

Permalink
Don't leave trailing whitespace when printing do-block expr (JuliaLan…
Browse files Browse the repository at this point in the history
…g#55738)

Before, when printing a `do`-block, we'd print a white-space after `do`
even if no arguments follow. Now we don't print that space.

---------

Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
nickrobinson251 and LilithHafner authored Sep 12, 2024
1 parent 6af5838 commit 7642856
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2196,8 +2196,12 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
elseif head === :do && nargs == 2
iob = IOContext(io, beginsym=>false)
show_unquoted(iob, args[1], indent, -1, quote_level)
print(io, " do ")
show_list(iob, (((args[2]::Expr).args[1])::Expr).args, ", ", 0, 0, quote_level)
print(io, " do")
do_args = (((args[2]::Expr).args[1])::Expr).args
if !isempty(do_args)
print(io, ' ')
show_list(iob, do_args, ", ", 0, 0, quote_level)
end
for stmt in (((args[2]::Expr).args[2])::Expr).args
print(io, '\n', " "^(indent + indent_width))
show_unquoted(iob, stmt, indent + indent_width, -1, quote_level)
Expand Down
5 changes: 5 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2768,3 +2768,8 @@ let topmi = ccall(:jl_new_method_instance_uninit, Ref{Core.MethodInstance}, ());
topmi.def = Main
@test contains(repr(topmi), "Toplevel MethodInstance")
end

@testset "show(<do-block expr>) no trailing whitespace" begin
do_expr1 = :(foo() do; bar(); end)
@test !contains(sprint(show, do_expr1), " \n")
end

0 comments on commit 7642856

Please sign in to comment.