diff --git a/src/typemap.c b/src/typemap.c index 5258f89ab9066..475981e170b46 100644 --- a/src/typemap.c +++ b/src/typemap.c @@ -83,6 +83,10 @@ static int sig_match_by_type_simple(jl_value_t **types, size_t n, jl_tupletype_t } if (va) { jl_value_t *decl = jl_field_type(sig, i); + if (jl_vararg_kind(decl) == JL_VARARG_INT) { + if (n-i != jl_unbox_long(jl_tparam1(decl))) + return 0; + } jl_value_t *t = jl_tparam0(decl); for(; i < n; i++) { if (!jl_subtype(types[i], t, 0)) @@ -150,6 +154,10 @@ static inline int sig_match_simple(jl_value_t **args, size_t n, jl_value_t **sig } if (va) { jl_value_t *decl = sig[i]; + if (jl_vararg_kind(decl) == JL_VARARG_INT) { + if (n-i != jl_unbox_long(jl_tparam1(decl))) + return 0; + } jl_value_t *t = jl_tparam0(decl); for(; i < n; i++) { if (!jl_subtype(args[i], t, 1)) diff --git a/test/core.jl b/test/core.jl index 4d9900fd815ec..de36aacfcfb43 100644 --- a/test/core.jl +++ b/test/core.jl @@ -600,11 +600,23 @@ Type11167{Float32,5} # dispatch let - local foo, bar, baz - foo(x::Tuple{Vararg{Any}})=0 - foo(x::Tuple{Vararg{Integer}})=1 - @test foo((:a,))==0 - @test foo(( 2,))==1 + local foo, foo2, fooN, bar, baz + foo(x::Tuple{Vararg{Any}}) = 0 + foo(x::Tuple{Vararg{Integer}}) = 1 + @test foo((:a,)) == 0 + @test foo(( 2,)) == 1 + + foo2(x::Vararg{Any,2}) = 2 + @test foo2(1,2) == 2 + @test_throws MethodError foo2(1) + @test_throws MethodError foo2(1,2,3) + + fooN{T,N}(A::Array{T,N}, x::Vararg{Any,N}) = -1 + @test fooN([1,2], 1) == -1 + @test_throws MethodError fooN([1,2], 1, 2) == -1 + @test fooN([1 2; 3 4], 1, 2) == -1 + @test_throws MethodError fooN([1 2; 3 4], 1) + @test_throws MethodError fooN([1 2; 3 4], 1, 2, 3) bar{T}(x::Tuple{T,T,T,T})=1 bar(x::Tuple{Any,Any,Any,Any})=2