Skip to content

Commit 37b7272

Browse files
vtjnashsimeonschaub
authored andcommitted
add a constructor for Union{} (JuliaLang#36863)
This often shows up accidentally in method intersections, which can force recompilation of completely unrelated code. Define this explicitly so that the compiler can always ignore this dispatch possibility.
1 parent 8a74d70 commit 37b7272

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

base/boot.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ ccall(:jl_toplevel_eval_in, Any, (Any, Any),
226226
(f::typeof(Typeof))(x) = ($(_expr(:meta,:nospecialize,:x)); isa(x,Type) ? Type{x} : typeof(x))
227227
end)
228228

229+
# let the compiler assume that calling Union{} as a constructor does not need
230+
# to be considered ever (which comes up often as Type{<:T})
231+
Union{}(a...) = throw(MethodError(Union{}, a))
232+
229233
macro nospecialize(x)
230234
_expr(:meta, :nospecialize, x)
231235
end

0 commit comments

Comments
 (0)