Skip to content

Commit

Permalink
allow an expression as the optional message in assert. fixes #5267
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 6, 2014
1 parent 5ed527f commit 652011f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ systemerror(p, b::Bool) = b ? throw(SystemError(string(p))) : nothing
## assertion functions and macros ##

assert(x) = x ? nothing : error("assertion failed")
macro assert(ex,msg...)
msg = isempty(msg) ? ex : msg[1]
if isdefined(Base,:string)
macro assert(ex,msgs...)
msg = isempty(msgs) ? ex : msgs[1]
if !isempty(msgs) && isa(msg, Expr)
# message is an expression needing evaluating
msg = :(string("assertion failed: ", $(esc(msg))))
elseif isdefined(Base,:string)
msg = string("assertion failed: ", msg)
else
# string() might not be defined during bootstrap
Expand Down

0 comments on commit 652011f

Please sign in to comment.