Skip to content

Commit 08d381a

Browse files
committed
Add invokelatest barrier to string(...) in @assert
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)
1 parent bee75f7 commit 08d381a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/error.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ macro assert(ex, msgs...)
232232
msg = msg # pass-through
233233
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
234234
# message is an expression needing evaluating
235-
msg = :(Main.Base.string($(esc(msg))))
235+
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
236236
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
237237
msg = Main.Base.string(msg)
238238
else
239239
# string() might not be defined during bootstrap
240-
msg = :(_assert_tostring($(Expr(:quote,msg))))
240+
msg = :(Main.Base.invokelatest(_assert_tostring, $(Expr(:quote,msg))))
241241
end
242242
return :($(esc(ex)) ? $(nothing) : throw(AssertionError($msg)))
243243
end

0 commit comments

Comments
 (0)