Skip to content

Commit a2b0e15

Browse files
committed
Add _assert_to_string indirection for Expr-evaluated @assert (#59298)
Not sure why this wasn't using this before since the code is effectively identical, but this allows: ```julia @Assert false "$("Hello,") assertion!" ``` to be `--trim`-"compatible" (unfortunately by deleting the assertion message...)
1 parent 975aa9e commit a2b0e15

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

base/error.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,12 @@ macro assert(ex, msgs...)
233233
msg = msg # pass-through
234234
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
235235
# message is an expression needing evaluating
236-
# N.B. To reduce the risk of invalidation caused by the complex callstack involved
237-
# with `string`, use `inferencebarrier` here to hide this `string` from the compiler.
238-
msg = :(Main.Base.inferencebarrier(Main.Base.string)($(esc(msg))))
236+
msg = :($_assert_tostring($(esc(msg))))
239237
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
240238
msg = Main.Base.string(msg)
241239
else
242240
# string() might not be defined during bootstrap
243-
msg = :(_assert_tostring($(Expr(:quote,msg))))
241+
msg = :($_assert_tostring($(Expr(:quote,msg))))
244242
end
245243
return :($(esc(ex)) ? $(nothing) : throw(AssertionError($msg)))
246244
end

0 commit comments

Comments
 (0)