Skip to content

Commit

Permalink
fix #44735, assert typeintersect arguments on Julia level
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Mar 27, 2022
1 parent 9d31f6a commit 32e9a9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})

0 comments on commit 32e9a9c

Please sign in to comment.