From 1545ac37605110d7c24668dffc36934b9e079317 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 20 Jul 2016 16:59:43 -0700 Subject: [PATCH] Fix pretty-printing of compact broadcast expressions and test. --- base/show.jl | 17 +++++++++++------ test/show.jl | 5 +++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/base/show.jl b/base/show.jl index 13be4e1e397b4..2e148085087ba 100644 --- a/base/show.jl +++ b/base/show.jl @@ -415,7 +415,8 @@ const expr_infix_wide = Set{Symbol}([ const expr_infix = Set{Symbol}([:(:), :(->), Symbol("::")]) const expr_infix_any = union(expr_infix, expr_infix_wide) const all_ops = union(quoted_syms, uni_ops, expr_infix_any) -const expr_calls = Dict(:call =>('(',')'), :calldecl =>('(',')'), :ref =>('[',']'), :curly =>('{','}')) +const expr_calls = Dict(:call => ('(',')'), :calldecl => ('(',')'), + :ref => ('[',']'), :curly => ('{','}'), :(.) => ('(',')')) const expr_parens = Dict(:tuple=>('(',')'), :vcat=>('[',']'), :hcat =>('[',']'), :row =>('[',']'), :vect=>('[',']')) @@ -546,6 +547,9 @@ function show_call(io::IO, head, func, func_args, indent) show_unquoted(io, func, indent) print(io, ')') end + if head == :(.) + print(io, '.') + end if !isempty(func_args) && isa(func_args[1], Expr) && func_args[1].head === :parameters print(io, op) show_list(io, func_args[2:end], ',', indent) @@ -665,8 +669,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) if !emphstate && ex.typ === Any show_type = false end - # dot (i.e. "x.y") - if is(head, :(.)) + # dot (i.e. "x.y"), but not compact broadcast exps + if is(head, :(.)) && !is_expr(args[2], :tuple) show_unquoted(io, args[1], indent + indent_width) print(io, '.') if is_quoted(args[2]) @@ -767,9 +771,10 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) show_call(io, head, func, func_args, indent) end - # other call-like expressions ("A[1,2]", "T{X,Y}") - elseif haskey(expr_calls, head) && nargs >= 1 # :ref/:curly/:calldecl - show_call(io, head, ex.args[1], ex.args[2:end], indent) + # other call-like expressions ("A[1,2]", "T{X,Y}", "f.(X,Y)") + elseif haskey(expr_calls, head) && nargs >= 1 # :ref/:curly/:calldecl/:(.) + funcargslike = head == :(.) ? ex.args[2].args : ex.args[2:end] + show_call(io, head, ex.args[1], funcargslike, indent) # comprehensions elseif (head === :typed_comprehension || head === :typed_dict_comprehension) && length(args) == 2 diff --git a/test/show.jl b/test/show.jl index bd028352d243f..b409214ac250d 100644 --- a/test/show.jl +++ b/test/show.jl @@ -561,3 +561,8 @@ end for op in (:(.=), :(.+=), :(.&=)) @test repr(parse("x $op y")) == ":(x $op y)" end + +# pretty-printing of compact broadcast expressions (#17289) +@test repr(:(f.(X,Y))) == ":(f.(X,Y))" +@test repr(:(f.(X))) == ":(f.(X))" +@test repr(:(f.())) == ":(f.())"