Skip to content

Commit

Permalink
fix #27352, disallow print/string of nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 27, 2018
1 parent 8c70b0a commit 93b29d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ function show(io::IO, tn::Core.TypeName)
end

show(io::IO, ::Nothing) = print(io, "nothing")
print(io::IO, ::Nothing) = throw(MethodError(print, (io, nothing)))
show(io::IO, b::Bool) = print(io, b ? "true" : "false")
show(io::IO, n::Signed) = (write(io, string(n)); nothing)
show(io::IO, n::Unsigned) = print(io, "0x", string(n, pad = sizeof(n)<<1, base = 16))
Expand Down
10 changes: 10 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1248,3 +1248,13 @@ h_line() = f_line()
│╻╷ f_line
││╻ g_line
││╻ g_line""")

# issue #27352
@test_throws MethodError print(nothing)
@test_throws MethodError print(stdout, nothing)
@test_throws MethodError string(nothing)
@test_throws MethodError string(1, "", nothing)
@test_throws MethodError let x = nothing; "x = $x" end
@test let x = nothing; "x = $(repr(x))" end == "x = nothing"
@test_throws MethodError `/bin/foo $nothing`
@test_throws MethodError `$nothing`

0 comments on commit 93b29d6

Please sign in to comment.