Skip to content

Commit a112382

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 ee2e27d commit a112382

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
@@ -2526,6 +2526,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
25262526
# we want to show bad ASTs reasonably to make errors understandable.
25272527
lambda_io = IOContext(io, :SOURCE_SLOTNAMES => false)
25282528
show_unquoted_expr_fallback(lambda_io, ex, indent, quote_level)
2529+
elseif get(io, beginsym, false) && head in (:begin, :end)
2530+
print(io, head)
25292531
else
25302532
unhandled = true
25312533
end

test/show.jl

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

23712371
# begin/end indices
23722372
@weak_test_repr "a[begin, end, (begin; end)]"
2373-
@test_broken repr(Base.remove_linenums!(:(a[begin, end, (begin; end)]))) == ":(a[begin, end, (begin;\n end)])"
2373+
@test repr(Base.remove_linenums!(:(a[begin, end, (begin; end)]))) == ":(a[begin, end, (begin;\n end)])"
23742374
@weak_test_repr "a[begin, end, let x=1; (x+1;); end]"
2375-
@test_broken repr(Base.remove_linenums!(:(a[begin, end, let x=1; (x+1;); end]))) ==
2375+
@test repr(Base.remove_linenums!(:(a[begin, end, let x=1; (x+1;); end]))) ==
23762376
":(a[begin, end, let x = 1\n begin\n x + 1\n end\n end])"
23772377
@test_repr "a[(bla;)]"
23782378
@test_repr "a[(;;)]"
23792379
@weak_test_repr "a[x -> f(x)]"
2380+
@test_broken @weak_test_repr """:([1,2,3,4][:end === :end ? end : var"end"])"""
23802381

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

0 commit comments

Comments
 (0)