From 66f336d37e123482c9fe5201750564537c420cbe Mon Sep 17 00:00:00 2001 From: Jake Bolewski Date: Tue, 11 Aug 2015 11:49:16 -0400 Subject: [PATCH] restrict Vararg{} to trailing position in Tuple type constructor --- src/builtins.c | 12 ++++++++++-- test/core.jl | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index a105e46ba0471..0bc6bdabcdd17 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1000,8 +1000,7 @@ JL_CALLABLE(jl_f_instantiate_type) { JL_NARGSV(instantiate_type, 1); if (args[0] == (jl_value_t*)jl_uniontype_type) { - size_t i; - for(i=1; i < nargs; i++) { + for(size_t i=1; i < nargs; i++) { jl_value_t* ty = args[i]; if ((!jl_is_type(ty) && !jl_is_typevar(ty)) || jl_is_vararg_type(ty)) { jl_type_error_rt("apply_type", "parameter of Union", @@ -1009,6 +1008,15 @@ JL_CALLABLE(jl_f_instantiate_type) } } } + else if (args[0] == (jl_value_t*)jl_tuple_type) { + for(size_t i=1; i < nargs; i++) { + jl_value_t* ty = args[i]; + if (jl_is_vararg_type(ty) && i != nargs-1) { + jl_type_error_rt("apply_type", "parameter of Tuple", + (jl_value_t*)jl_type_type, args[i]); + } + } + } else if (!jl_is_datatype(args[0])) { JL_TYPECHK(instantiate_type, typector, args[0]); } diff --git a/test/core.jl b/test/core.jl index b2719de645b53..aa9938207fc72 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3203,3 +3203,7 @@ end # don't allow Vararg{} in Union{} type constructor @test_throws TypeError Union{Int,Vararg{Int}} + +# don't allow Vararg{} in Tuple{} type constructor in non-trailing position +@test_throws TypeError Tuple{Vararg{Int32},Int64,Float64} +@test_throws TypeError Tuple{Int64,Vararg{Int32},Float64}