Skip to content

Commit b4e0eb7

Browse files
committed
Partial fix for printing
Two things to fix: - We do correct-but-ugly printing of `end` when it's inside another expression (probably due to setting beginsym to false too often) - `show` doesn't play nicely with ternary expressions, which seems like an unrelated issue.
1 parent 7ba922c commit b4e0eb7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

base/show.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
25422542
# we want to show bad ASTs reasonably to make errors understandable.
25432543
lambda_io = IOContext(io, :SOURCE_SLOTNAMES => false)
25442544
show_unquoted_expr_fallback(lambda_io, ex, indent, quote_level)
2545+
elseif get(io, beginsym, false) && head in (:begin, :end)
2546+
print(io, head)
25452547
else
25462548
unhandled = true
25472549
end

test/show.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,13 +2377,14 @@ end
23772377

23782378
# begin/end indices
23792379
@weak_test_repr "a[begin, end, (begin; end)]"
2380-
@test_broken repr(Base.remove_linenums!(:(a[begin, end, (begin; end)]))) == ":(a[begin, end, (begin;\n end)])"
2380+
@test repr(Base.remove_linenums!(:(a[begin, end, (begin; end)]))) == ":(a[begin, end, (begin;\n end)])"
23812381
@weak_test_repr "a[begin, end, let x=1; (x+1;); end]"
2382-
@test_broken repr(Base.remove_linenums!(:(a[begin, end, let x=1; (x+1;); end]))) ==
2382+
@test repr(Base.remove_linenums!(:(a[begin, end, let x=1; (x+1;); end]))) ==
23832383
":(a[begin, end, let x = 1\n begin\n x + 1\n end\n end])"
23842384
@test_repr "a[(bla;)]"
23852385
@test_repr "a[(;;)]"
23862386
@weak_test_repr "a[x -> f(x)]"
2387+
@test_broken @weak_test_repr """:([1,2,3,4][:end === :end ? end : var"end"])"""
23872388

23882389
@testset "Base.Iterators" begin
23892390
@test sprint(show, enumerate("test")) == "enumerate(\"test\")"

0 commit comments

Comments
 (0)