Skip to content

Commit

Permalink
remove isvarargtype assertions from subtype and intersect
Browse files Browse the repository at this point in the history
fix #44735
  • Loading branch information
aviatesk committed Apr 6, 2022
1 parent 2c8c0a4 commit 529b69d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,17 @@ struct type with no fields.
issingletontype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && isdefined(t, :instance))

"""
typeintersect(T, S)
typeintersect(T::Type, S::Type)
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
isa(a, Type) || throw(TypeError(:typeintersect, Type, typeof(a)))
isa(b, Type) || throw(TypeError(:typeintersect, Type, typeof(b)))
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
2 changes: 0 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,6 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
}
if (jl_is_unionall(y))
return subtype_unionall(x, (jl_unionall_t*)y, e, 1, param);
assert(!jl_is_vararg(x) && !jl_is_vararg(y));
if (jl_is_datatype(x) && jl_is_datatype(y)) {
if (x == y) return 1;
if (y == (jl_value_t*)jl_any_type) return 1;
Expand Down Expand Up @@ -3107,7 +3106,6 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
}
if (jl_is_unionall(y))
return intersect_unionall(x, (jl_unionall_t*)y, e, 1, param);
assert(!jl_is_vararg(x) && !jl_is_vararg(y));
if (jl_is_datatype(x) && jl_is_datatype(y)) {
jl_datatype_t *xd = (jl_datatype_t*)x, *yd = (jl_datatype_t*)y;
if (param < 2) {
Expand Down
6 changes: 6 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1976,3 +1976,9 @@ 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)

# https://github.com/JuliaLang/julia/issues/44735
@test_throws TypeError(:typeintersect, Type, Core.TypeofVararg) typeintersect(Vararg{Int}, Int)
@test_throws TypeError(:typeintersect, Type, Core.TypeofVararg) typeintersect(Int, Vararg{Int})
@test_throws TypeError(:typeintersect, Type, Int) typeintersect(1, Int)
@test_throws TypeError(:typeintersect, Type, Int) typeintersect(Int, 1)

0 comments on commit 529b69d

Please sign in to comment.