Skip to content

Commit 1a23e20

Browse files
committed
fix #17354, expand Tuple{Vararg{Any,2}} on construction
1 parent f8d67f7 commit 1a23e20

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/jltypes.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,28 +2155,22 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
21552155
if (nt < 0)
21562156
jl_errorf("apply_type: Vararg length N is negative: %zd", nt);
21572157
va = jl_tparam0(va);
2158-
if (nt == 0 || jl_is_leaf_type(va)) {
2158+
if (nt == 0 || !jl_has_typevars(va)) {
21592159
if (ntp == 1)
21602160
return jl_tupletype_fill(nt, va);
21612161
size_t i, l;
2162+
p = jl_alloc_svec(ntp - 1 + nt);
21622163
for (i = 0, l = ntp - 1; i < l; i++) {
2163-
if (!jl_is_leaf_type(iparams[i]))
2164-
break;
2164+
jl_svecset(p, i, iparams[i]);
21652165
}
2166-
if (i == l) {
2167-
p = jl_alloc_svec(ntp - 1 + nt);
2168-
for (i = 0, l = ntp - 1; i < l; i++) {
2169-
jl_svecset(p, i, iparams[i]);
2170-
}
2171-
l = ntp - 1 + nt;
2172-
for (; i < l; i++) {
2173-
jl_svecset(p, i, va);
2174-
}
2175-
JL_GC_PUSH1(&p);
2176-
jl_value_t *ndt = (jl_value_t*)jl_apply_tuple_type(p);
2177-
JL_GC_POP();
2178-
return ndt;
2166+
l = ntp - 1 + nt;
2167+
for (; i < l; i++) {
2168+
jl_svecset(p, i, va);
21792169
}
2170+
JL_GC_PUSH1(&p);
2171+
jl_value_t *ndt = (jl_value_t*)jl_apply_tuple_type(p);
2172+
JL_GC_POP();
2173+
return ndt;
21802174
}
21812175
}
21822176
}

test/core.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ let N = TypeVar(:N,true)
139139
@test is(Bottom,typeintersect(Tuple{Array{Int,N},Vararg{Int,N}}, Tuple{Vector{Int},Real,Real,Real}))
140140
@test is(Bottom,typeintersect(Tuple{Vector{Int},Real,Real,Real}, Tuple{Array{Int,N},Vararg{Int,N}}))
141141
@test Tuple{Int,Vararg{Int,2}} == Tuple{Int,Int,Int}
142+
@test Tuple{Int,Vararg{Int,2}} === Tuple{Int,Int,Int}
143+
@test Tuple{Any, Any} === Tuple{Vararg{Any,2}}
142144
@test Tuple{Int,Vararg{Int,2}} == Tuple{Int,Int,Vararg{Int,1}}
143145
@test Tuple{Int,Vararg{Int,2}} == Tuple{Int,Int,Int,Vararg{Int,0}}
144146
@test !(Tuple{Int,Vararg{Int,2}} <: Tuple{Int,Int,Int,Vararg{Int,1}})

0 commit comments

Comments
 (0)