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

Function do not accept keywords when Vararg is used. #13919

Closed
dhoegh opened this issue Nov 8, 2015 · 4 comments · Fixed by #17673
Closed

Function do not accept keywords when Vararg is used. #13919

dhoegh opened this issue Nov 8, 2015 · 4 comments · Fixed by #17673
Assignees

Comments

@dhoegh
Copy link
Contributor

dhoegh commented Nov 8, 2015

If Vararg{T} is used in a function definition, the function cannot have keywords. It fails due to some lowering issue. If the following is functions are defined.

test(x::Vararg{Int}; key=100) = println("x=$x\nkey=$key")
test1(x::Vararg{Int}) = println("x=$x")
test1(1, 2) # print x=(1,2)
test(1, 2)  #Fails with

LoadError: MethodError: `__test#33__` has no method matching __test#33__(::Int64, ::Tuple{Int64,Int64})
Closest candidates are:
  __test#33__(::Any, !Matched::Int64...)
while loading In[59], in expression starting on line 1

test1 function works as intended while test fails.
@code_lowered test(1, 2) returns

1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:(x::(top(apply_type))(Vararg,Int))], Any[Any[Any[:x,:Any,0]],Any[],0,Any[]], :(begin 
        $(Expr(:line, 1, symbol("In[52]"), symbol("")))
        return (Main.__test#33__)(100,x)
    end))))

It seems to call a function named __test#33__ which do not exist. If the function is defined without a keyword argument code lowered calls println
@code_lowered test1(1, 2)


1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:(x::(top(apply_type))(Vararg,Int))], Any[Any[Any[:x,:Any,0]],Any[],0,Any[]], :(begin  # In[52], line 2:
        return (Main.println)((top(string))("x=",x))
    end))))
@dhoegh
Copy link
Contributor Author

dhoegh commented Nov 8, 2015

I have found another way of obtaining the same solution.

test(x::Int...;key=100) = println("x=$x\nkey=$key")

I do not know if it is supposed to work with Vararg{Int}.

@JeffBezanson
Copy link
Sponsor Member

This is a strange failure mode, but this is not supposed to work. The ... syntax is the normal varargs syntax.

@dhoegh
Copy link
Contributor Author

dhoegh commented Jul 29, 2016

@pwl could you check if your issue in SciML/ODE.jl#49 (comment) is fixed on latest master of Julia, if not fill a new issue?

@pwl
Copy link
Contributor

pwl commented Jul 29, 2016

We have already moved away from that solution so there is no way for me to verify your fix apart from running your tests.

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

Successfully merging a pull request may close this issue.

3 participants