Skip to content

Commit

Permalink
fix #27352, disallow print/string of nothing (#27829)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jun 28, 2018
1 parent 842bddd commit a5e3460
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function print_node(io::IO, idx::Int, @nospecialize(stmt), used, argnames, maxsi
Base.print(io, join(String[sprint(io->print_ssa(io, arg, argnames)) for arg in stmt.args], ", "))
Base.print(io, ")")
else
Base.print(io, stmt)
Base.show(io, stmt)
end
end

Expand Down
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 a5e3460

Please sign in to comment.