Skip to content

Commit 5957a5f

Browse files
committed
fix show() of 1-argument calls to binary operators
we were doing this: ``` julia> :((%)(x)) :(x) ```
1 parent 85d13db commit 5957a5f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

base/show.jl

+15-6
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,27 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
412412

413413
# binary operator (i.e. "x + y")
414414
elseif func in bin_ops
415-
sep = func_prec >= bin_op_precs[:(^)] ? "$func" : " $func "
416-
if func_prec <= prec
417-
show_enclosed_list(io, '(', func_args, sep, ')', indent, func_prec)
415+
if length(func_args) > 1
416+
sep = func_prec >= bin_op_precs[:(^)] ? "$func" : " $func "
417+
if func_prec <= prec
418+
show_enclosed_list(io, '(', func_args, sep, ')', indent, func_prec)
419+
else
420+
show_list(io, func_args, sep, indent, func_prec)
421+
end
418422
else
419-
show_list(io, func_args, sep, indent, func_prec)
423+
# 1-argument call to normally-binary operator
424+
op, cl = expr_calls[head]
425+
print(io, "(")
426+
show_unquoted(io, func, indent)
427+
print(io, ")")
428+
show_enclosed_list(io, op, func_args, ",", cl, indent)
420429
end
421430

422431
# normal function (i.e. "f(x,y)")
423432
else
424433
op, cl = expr_calls[head]
425-
show_unquoted(io, args[1], indent)
426-
show_enclosed_list(io, op, args[2:end], ",", cl, indent)
434+
show_unquoted(io, func, indent)
435+
show_enclosed_list(io, op, func_args, ",", cl, indent)
427436
end
428437
elseif is(head, :ccall)
429438
show_unquoted(io, :ccall, indent)

0 commit comments

Comments
 (0)