Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction b/w Vararg and keyword arguments #17031

Closed
davidagold opened this issue Jun 20, 2016 · 2 comments
Closed

Interaction b/w Vararg and keyword arguments #17031

davidagold opened this issue Jun 20, 2016 · 2 comments

Comments

@davidagold
Copy link
Contributor

On Julia Version 0.5.0-dev+4810, the following works:

julia> f(x::Int...; kwarg=false) = kwarg
f (generic function with 1 method)

julia> f(1, 2, 3; kwarg=true)
true

However, defining a function with both a Vararg argument and a keyword argument seems to generate a method that is missed(?) by dispatch:

julia> g{nargs}(x::Vararg{Int, nargs}; kwarg=false) = kwarg
g (generic function with 1 method)

julia> g(1, 2, 3; kwarg=true)
ERROR: MethodError: no method matching #g#2(::Bool, ::#g, ::Tuple{Int64,Int64,Int64})
Closest candidates are:
  #g#2{nargs}(::Any, ::Any, ::Int64...)
 in (::#kw##g)(::Array{Any,1}, ::#g, ::Int64, ::Int64, ::Int64) at ./null:0
 in eval(::Module, ::Any) at ./boot.jl:231
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

julia> @code_typed g(1, 2, 3; kwarg=true)
1-element Array{Any,1}:
 LambdaInfo for g
:(begin  # REPL[28], line 1:
        return (Main.#g#2)(false,#self#,x)
    end)
@dhoegh
Copy link
Contributor

dhoegh commented Jun 20, 2016

This is a dup of #13919.

@JeffBezanson
Copy link
Sponsor Member

Closing as dup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants