From 0b2f6de87ea950c7511048239df4688ccc24b5ed Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 9 Jun 2017 10:28:19 -0400 Subject: [PATCH] fix bug in setting `ninitialized` of vararg tuples --- src/jltypes.c | 4 +++- test/tuple.jl | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/jltypes.c b/src/jltypes.c index c292cae8e523e..34ef0c3160547 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -1058,7 +1058,9 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i JL_GC_PUSH2(&p, &ndt); jl_value_t *last = iparams[ntp - 1]; + int isvatuple = 0; if (istuple && ntp > 0 && jl_is_vararg_type(last)) { + isvatuple = 1; // normalize Tuple{..., Vararg{Int, 3}} to Tuple{..., Int, Int, Int} jl_value_t *va = jl_unwrap_unionall(last); jl_value_t *va0 = jl_tparam0(va), *va1 = jl_tparam1(va); @@ -1185,7 +1187,7 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i } } if (istuple) - ndt->ninitialized = ntp; + ndt->ninitialized = ntp - isvatuple; else ndt->ninitialized = dt->ninitialized; diff --git a/test/tuple.jl b/test/tuple.jl index 2385e52a9ef4f..cbe3ccd205e3f 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -260,3 +260,9 @@ end for n = 0:15 @test ntuple(identity, Val{n}) == ntuple(identity, n) end + +# Tuple type ninitialized +@test Tuple{Int,Any}.ninitialized == 2 +@test Tuple.ninitialized == 0 +@test Tuple{Int,Vararg{Any}}.ninitialized == 1 +@test Tuple{Any,Any,Vararg{Any}}.ninitialized == 2