Skip to content

Commit 6d78404

Browse files
authored
remove isvarargtype assertions from subtype and intersect (#44761)
fix #44735
1 parent 244ada3 commit 6d78404

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

base/reflection.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,12 @@ struct type with no fields.
675675
issingletontype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && isdefined(t, :instance))
676676

677677
"""
678-
typeintersect(T, S)
678+
typeintersect(T::Type, S::Type)
679679
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+
typeintersect(@nospecialize(a), @nospecialize(b)) = (@_pure_meta; ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type))
684684

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

src/subtype.c

-2
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
12581258
}
12591259
if (jl_is_unionall(y))
12601260
return subtype_unionall(x, (jl_unionall_t*)y, e, 1, param);
1261-
assert(!jl_is_vararg(x) && !jl_is_vararg(y));
12621261
if (jl_is_datatype(x) && jl_is_datatype(y)) {
12631262
if (x == y) return 1;
12641263
if (y == (jl_value_t*)jl_any_type) return 1;
@@ -3107,7 +3106,6 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
31073106
}
31083107
if (jl_is_unionall(y))
31093108
return intersect_unionall(x, (jl_unionall_t*)y, e, 1, param);
3110-
assert(!jl_is_vararg(x) && !jl_is_vararg(y));
31113109
if (jl_is_datatype(x) && jl_is_datatype(y)) {
31123110
jl_datatype_t *xd = (jl_datatype_t*)x, *yd = (jl_datatype_t*)y;
31133111
if (param < 2) {

test/subtype.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1976,3 +1976,9 @@ 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+
# https://github.com/JuliaLang/julia/issues/44735
1981+
@test_throws TypeError(:typeassert, Type, Vararg{Int}) typeintersect(Vararg{Int}, Int)
1982+
@test_throws TypeError(:typeassert, Type, Vararg{Int}) typeintersect(Int, Vararg{Int})
1983+
@test_throws TypeError(:typeassert, Type, 1) typeintersect(1, Int)
1984+
@test_throws TypeError(:typeassert, Type, 1) typeintersect(Int, 1)

0 commit comments

Comments
 (0)