Skip to content

Commit

Permalink
restrict Vararg{} to trailing position in Tuple type constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Aug 11, 2015
1 parent 39d2ef6 commit 66f336d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,23 @@ 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",
(jl_value_t*)jl_type_type, args[i]);
}
}
}
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]);
}
Expand Down
4 changes: 4 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 66f336d

Please sign in to comment.