Skip to content

Commit c86965b

Browse files
topolarityKristofferC
authored andcommitted
Add invokelatest barrier to string(...) in @assert (#55739)
This change protects `@assert` from invalidations to `Base.string(...)` by adding an `invokelatest` barrier. A common source of invalidations right now is `print(io, join(args...))`. The problem is: 1. Inference concludes that `join(::Any...)` returns `Union{String,AnnotatedString}` 2. The `print` call is union-split to `String` and `AnnotatedString` 3. This code is now invalidated when StyledStrings defines `print(io, ::AnnotatedString)` The invalidation chain for `@assert` is similar: ` @Assert 1 == 1` calls into `string(::Expr)` which calls into `print(io, join(args::Any...))`. Unfortunately that leads to the invalidation of almost all `@assert`s without an explicit error message Similar to #55583 (comment) (cherry picked from commit 945517b)
1 parent 47e8cab commit c86965b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/error.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ macro assert(ex, msgs...)
223223
msg = msg # pass-through
224224
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
225225
# message is an expression needing evaluating
226-
msg = :(Main.Base.string($(esc(msg))))
226+
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
227227
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
228228
msg = Main.Base.string(msg)
229229
else
230230
# string() might not be defined during bootstrap
231231
msg = quote
232232
msg = $(Expr(:quote,msg))
233-
isdefined(Main, :Base) ? Main.Base.string(msg) :
233+
isdefined(Main, :Base) ? Main.Base.invokelatest(Main.Base.string, msg) :
234234
(Core.println(msg); "Error during bootstrap. See stdout.")
235235
end
236236
end

0 commit comments

Comments
 (0)