Skip to content

Commit

Permalink
Add invokelatest barrier to string(...) in @assert
Browse files Browse the repository at this point in the history
This change protects `@assert` from invalidations to `Base.string(...)`
which are fairly easy to trigger.

Perhaps the worst offender right now is `using StyledStrings`
which invalidates `string(::Expr)`, which unfortunately leads to
invalidation of almost `@assert`s (without an explicit message)
  • Loading branch information
topolarity committed Sep 11, 2024
1 parent 255162c commit ad3abc2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ macro assert(ex, msgs...)
msg = msg # pass-through
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
# message is an expression needing evaluating
msg = :(Main.Base.string($(esc(msg))))
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
msg = Main.Base.string(msg)
else
# string() might not be defined during bootstrap
msg = :(_assert_tostring($(Expr(:quote,msg))))
msg = :(Main.Base.invokelatest(_assert_tostring, $(Expr(:quote,msg))))
end
return :($(esc(ex)) ? $(nothing) : throw(AssertionError($msg)))
end
Expand Down

0 comments on commit ad3abc2

Please sign in to comment.