Skip to content

Commit

Permalink
raise exception on Vararg-arguments in subtype rather than abort
Browse files Browse the repository at this point in the history
fix #44735
  • Loading branch information
aviatesk committed Apr 4, 2022
1 parent 51271e0 commit 3d9389e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,8 @@ 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));
else if (jl_is_vararg(x) || jl_is_vararg(y))
jl_errorf("invalid subtyping with Vararg");
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
4 changes: 4 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1976,3 +1976,7 @@ 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 ErrorException("invalid subtyping with Vararg") typeintersect(Vararg{Int}, Int)
@test_throws ErrorException("invalid subtyping with Vararg") typeintersect(Int, Vararg{Int})

0 comments on commit 3d9389e

Please sign in to comment.