Skip to content

Commit c696822

Browse files
committed
fix #44735, assert typeintersect arguments on Julia level
1 parent 1f1b752 commit c696822

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/reflection.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,11 @@ issingletontype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && isdefined(
680680
Compute a type that contains the intersection of `T` and `S`. Usually this will be the
681681
smallest such type or one close to it.
682682
"""
683-
typeintersect(@nospecialize(a), @nospecialize(b)) = (@_pure_meta; ccall(:jl_type_intersection, Any, (Any, Any), a, b))
683+
function typeintersect(@nospecialize(a), @nospecialize(b))
684+
@_pure_meta
685+
(!isvarargtype(a) && !isvarargtype(b)) || throw(ArgumentError("invalid typeintersect with Vararg"))
686+
return ccall(:jl_type_intersection, Any, (Any, Any), a, b)
687+
end
684688

685689
morespecific(@nospecialize(a), @nospecialize(b)) = ccall(:jl_type_morespecific, Cint, (Any, Any), a, b) != 0
686690

test/subtype.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,3 +1976,6 @@ end
19761976
@testintersect(Tuple{Type{Pair{_A, S} where S<:AbstractArray{<:_A, 2}}, Dict} where _A,
19771977
Tuple{Type{Pair{_A, S} where S<:AbstractArray{<:_A, 2}} where _A, Union{Array, Pair}},
19781978
Bottom)
1979+
1980+
@test_throws ArgumentError typeintersect(Vararg{Int}, Int)
1981+
@test_throws ArgumentError typeintersect(Int, Vararg{Int})

0 commit comments

Comments
 (0)