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

Method dispatch dependent upon call order #6426

Closed
mbauman opened this issue Apr 5, 2014 · 1 comment
Closed

Method dispatch dependent upon call order #6426

mbauman opened this issue Apr 5, 2014 · 1 comment
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@mbauman
Copy link
Member

mbauman commented Apr 5, 2014

If I define a function with the following methods:

f(x,args...) = f(x,map(a->(isa(a,Type) ? Type{a} : typeof(a)), args))
f(x,t::(Type...)) = print(t)

Julia's dispatch behavior is dependent upon which I call first. Note that the first (unused) argument is required to trigger this.

$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+2494 (2014-04-04 23:25 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 7d495c0 (0 days old master)
|__/                   |  x86_64-apple-darwin13.1.0

julia> f(x,args...) = f(x,map(a->(isa(a,Type) ? Type{a} : typeof(a)), args))
       f(x,t::(Type...)) = print(t)
f (generic function with 2 methods)

julia> f(1,(1,2)) # A dispatch loop to itself?
^CERROR: interrupt
 in anonymous at none:1
 in f at none:1 (repeats 1192 times)

julia> exit()

$ julia --quiet
julia> f(x,args...) = f(x,map(a->(isa(a,Type) ? Type{a} : typeof(a)), args))
       f(x,t::(Type...)) = print(t)
f (generic function with 2 methods)

julia> f(1,(Int,)) # Call the second method first
(Int64,)
julia> f(1,(1,2)) # And now the first method works as expected!
((Int64,Int64),)
@JeffBezanson
Copy link
Member

Likely a dup of #5577

@JeffBezanson JeffBezanson self-assigned this Apr 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants