Skip to content

Commit

Permalink
Add parens to unary operator expression printing
Browse files Browse the repository at this point in the history
Have Expr(:call,:+,:+) print as ":(+(+))" instead of ":(++)"
  • Loading branch information
jdlangs committed Jun 12, 2015
1 parent b2a9a02 commit cce4443
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
# unary operator (i.e. "!z")
elseif isa(func,Symbol) && func in uni_ops && length(func_args) == 1
show_unquoted(io, func, indent)
if isa(func_args[1], Expr) || length(func_args) > 1
#for safety, always wrap a call on an operator in parens
arg_is_op = func_args[1] in union(uni_ops, expr_infix_any)
if arg_is_op || isa(func_args[1], Expr)
show_enclosed_list(io, '(', func_args, ",", ')', indent, func_prec)
else
show_unquoted(io, func_args[1])
Expand Down

0 comments on commit cce4443

Please sign in to comment.