diff --git a/base/reflection.jl b/base/reflection.jl index f114949ba6fd3..b2eef3f920fe4 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -680,7 +680,11 @@ issingletontype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && isdefined( Compute a type that contains the intersection of `T` and `S`. Usually this will be the smallest such type or one close to it. """ -typeintersect(@nospecialize(a), @nospecialize(b)) = (@_pure_meta; ccall(:jl_type_intersection, Any, (Any, Any), a, b)) +function typeintersect(@nospecialize(a), @nospecialize(b)) + @_pure_meta + (!isvarargtype(a) && !isvarargtype(b)) || throw(ArgumentError("invalid typeintersect with Vararg")) + return ccall(:jl_type_intersection, Any, (Any, Any), a, b) +end morespecific(@nospecialize(a), @nospecialize(b)) = ccall(:jl_type_morespecific, Cint, (Any, Any), a, b) != 0 diff --git a/test/subtype.jl b/test/subtype.jl index 3eca685aee84c..c8c5e091acf65 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1976,3 +1976,6 @@ end @testintersect(Tuple{Type{Pair{_A, S} where S<:AbstractArray{<:_A, 2}}, Dict} where _A, Tuple{Type{Pair{_A, S} where S<:AbstractArray{<:_A, 2}} where _A, Union{Array, Pair}}, Bottom) + +@test_throws ArgumentError typeintersect(Vararg{Int}, Int) +@test_throws ArgumentError typeintersect(Int, Vararg{Int})