From 7593fc3d74e073dc5046e047901b6a86bcfb64a9 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Thu, 29 Jan 2026 22:43:58 +0100 Subject: [PATCH 1/2] merge the three methods of `error` into a single method Allows to avoid special-casing `max_methods` for this function. --- base/error.jl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/base/error.jl b/base/error.jl index 303b516357278..17b14ead6af60 100644 --- a/base/error.jl +++ b/base/error.jl @@ -27,22 +27,14 @@ throw ## native julia error handling ## -# This is `Experimental.@max_methods 2 function error end`, which is not available at this point in bootstrap. -# NOTE It is important to always be able to infer the return type of `error` as `Union{}`, -# but there's a hitch when a package globally sets `@max_methods 1` and it causes inference -# for `error(::Any)` to fail (JuliaLang/julia#54029). -# This definition site `@max_methods 2` setting overrides any global `@max_methods 1` settings -# on package side, guaranteeing that return type inference on `error` is successful always. function error end -typeof(error).name.max_methods = UInt8(2) """ error(message::AbstractString) Raise an `ErrorException` with the given message. """ -error(s::AbstractString) = throw(ErrorException(s)) -error() = throw(ErrorException("")) +error(::AbstractString) """ error(msg...) @@ -51,7 +43,14 @@ Raise an `ErrorException` with a message constructed by `string(msg...)`. """ function error(s::Vararg{Any,N}) where {N} @noinline - throw(ErrorException(Main.Base.string(s...))) + exc = if s === () + ErrorException("") + elseif s isa Tuple{AbstractString} + ErrorException(s...) + else + ErrorException(Main.Base.string(s...)) + end + throw(exc) end """ From ca2726d3ab7e37c20f58e90fe4d8c5c1529a2c85 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Thu, 29 Jan 2026 22:57:17 +0100 Subject: [PATCH 2/2] add back comment --- base/error.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/base/error.jl b/base/error.jl index 17b14ead6af60..c2ccd5af361c4 100644 --- a/base/error.jl +++ b/base/error.jl @@ -27,6 +27,9 @@ throw ## native julia error handling ## +# NOTE It is important to always be able to infer the return type of `error` as `Union{}`, +# see issue (JuliaLang/julia#54029). Ensure that method counts are small enough with +# respect to the `max_methods` value of the function. function error end """