diff --git a/base/error.jl b/base/error.jl index e25157b6f2b957..a318dc9768100d 100644 --- a/base/error.jl +++ b/base/error.jl @@ -223,14 +223,16 @@ 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.invokelatest(Main.Base.string, $(esc(msg)))) + # N.B. To reduce the risk of invalidation caused by the complex callstack involved + # with `string`, use `inferencebarrier` here to hide this `string` from the compiler. + msg = :(Main.Base.inferencebarrier(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 = quote msg = $(Expr(:quote,msg)) - isdefined(Main, :Base) ? Main.Base.invokelatest(Main.Base.string, msg) : + isdefined(Main, :Base) ? Main.Base.inferencebarrier(Main.Base.string, msg) : (Core.println(msg); "Error during bootstrap. See stdout.") end end