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

Default arguments are leaking between methods #32767

Closed
HFriberg opened this issue Aug 2, 2019 · 2 comments
Closed

Default arguments are leaking between methods #32767

HFriberg opened this issue Aug 2, 2019 · 2 comments

Comments

@HFriberg
Copy link

HFriberg commented Aug 2, 2019

The following function has a default argument of incompatible type. When calling foo() it looks for foo(::String) which fails with an amusing closest candidate suggestion -- perhaps I meant to call foo()? 😃 This is not too bad though..

julia> function foo(x::Integer="hello")
         return 13
       end
foo (generic function with 2 methods)

julia> foo()
ERROR: MethodError: no method matching foo(::String)
Closest candidates are:
  foo() at REPL[1]:2
  foo(::Integer) at REPL[1]:2
Stacktrace:
 [1] foo() at ./REPL[1]:2
 [2] top-level scope at none:0

What worries me is that the default argument of this method can leak to other methods of foo, as when I continue the example from above with this:

julia> function foo(x::String)
         return x * " world"
       end
foo (generic function with 3 methods)

julia> foo()
"hello world"

This must be a dispatching bug of some sort?

@yuyichao
Copy link
Contributor

yuyichao commented Aug 2, 2019

Dup of #7357
Not a dispatch bug.

@KristofferC
Copy link
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