Skip to content

Commit 92ac59a

Browse files
vtjnashtimholy
authored andcommitted
normalize more Tuple{Vararg{T,N}} to Tuple{T,...}
c.f. "Instantiate Tuple{Vararg{Int,3}} as Tuple{Int,Int,Int}"
1 parent c66aeb3 commit 92ac59a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/jltypes.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,18 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
20572057
if (stack_lkup)
20582058
return stack_lkup;
20592059

2060+
if (istuple && ntp == 1 && jl_is_vararg_type(iparams[0])) {
2061+
// normalize Tuple{Vararg{Int,3}} to Tuple{Int,Int,Int}
2062+
jl_datatype_t *va = (jl_datatype_t*)iparams[0];
2063+
if (jl_is_long(jl_tparam1(va))) {
2064+
ssize_t nt = jl_unbox_long(jl_tparam1(va));
2065+
if (nt < 0)
2066+
jl_errorf("apply_type: Vararg length N is negative: %zd", nt);
2067+
if (jl_is_leaf_type(jl_tparam0(va)))
2068+
return jl_tupletype_fill(nt, jl_tparam0(va));
2069+
}
2070+
}
2071+
20602072
// always use original type constructor
20612073
if (!istuple) {
20622074
if (jl_is_vararg_type((jl_value_t*)dt) && ntp == 2) {
@@ -2164,15 +2176,6 @@ static void check_tuple_parameter(jl_value_t *pi, size_t i, size_t np)
21642176

21652177
static jl_tupletype_t *jl_apply_tuple_type_v_(jl_value_t **p, size_t np, jl_svec_t *params)
21662178
{
2167-
if (np == 1 && jl_is_vararg_type(p[0])) {
2168-
jl_datatype_t *va = (jl_datatype_t*)p[0];
2169-
if (jl_is_long(jl_tparam1(va))) {
2170-
ssize_t nt = jl_unbox_long(jl_tparam1(va));
2171-
if (nt < 0)
2172-
jl_errorf("size or dimension is negative: %zd", nt);
2173-
return (jl_tupletype_t*)jl_tupletype_fill(nt, jl_tparam0(va));
2174-
}
2175-
}
21762179
int isabstract = 0, cacheable = 1;
21772180
for(size_t i=0; i < np; i++) {
21782181
jl_value_t *pi = p[i];

0 commit comments

Comments
 (0)