Skip to content

Commit

Permalink
Special-case Vararg handling when contained in an NTuple.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Sep 13, 2023
1 parent 24a1a7c commit dc58703
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,23 @@ static jl_value_t *inst_tuple_w_(jl_value_t *t, jl_typeenv_t *env, jl_typestack_
int i;
for (i = 0; i < ntp; i++) {
jl_value_t *elt = jl_svecref(tp, i);
jl_value_t *pi = inst_type_w_(elt, env, stack, check);
jl_value_t *pi;
if (jl_is_vararg(elt)) {
// special-case Vararg when contained in Tuple: normally we disallow non-type T,
// but NTuple{2,N} should work for StaticArrays.jl (see JuliaLang/julia#51244).
jl_vararg_t *va = (jl_vararg_t*)elt;
jl_value_t *T = NULL;
if (va->T && !jl_is_type(va->T) && !jl_is_typevar(va->T)) {
// temporarily swap out Vararg{T} for Vararg{Any}
T = va->T;
va->T = (jl_value_t*) jl_any_type;
}
pi = inst_type_w_(elt, env, stack, check);
if (T)
((jl_vararg_t*)pi)->T = T;
} else {
pi = inst_type_w_(elt, env, stack, check);
}
iparams[i] = pi;
if (ip_heap)
jl_gc_wb(ip_heap, pi);
Expand Down
10 changes: 10 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8097,3 +8097,13 @@ end
let lin = Core.LineInfoNode(Base, first(methods(convert)), :foo, Int32(5), Int32(0))
@test convert(LineNumberNode, lin) == LineNumberNode(5, :foo)
end

# JuliaLang/julia#51228: bad Varargs should be disallowed
let
@test_throws TypeError Vararg{2,2}
# ... but should still be allowed inside of a Tuple
@test_broken Tuple{Vararg{2,2}} === Tuple{2,2}
# ... because it's used for the NTuple definition
@test NTuple{2,2} === Tuple{2,2}
# ... which is used by e.g. StaticArrays.jl
end

0 comments on commit dc58703

Please sign in to comment.