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 ambiguity error #20670

Closed
marius311 opened this issue Feb 19, 2017 · 6 comments
Closed

Method ambiguity error #20670

marius311 opened this issue Feb 19, 2017 · 6 comments

Comments

@marius311
Copy link
Contributor

The following on 0.5 and on master gives a method ambiguity error:

module test

abstract foo{T<:Real}
immutable bar{T} <: foo{T} end

f(a::foo, b::foo) = 1
f{T<:bar}(a::T, b::T) = 2

f(bar{Int}(),bar{Int}()) # ambiguous

end

I do realize f{T<:bar}(a::T, b::T) = 2 instead of just f(a::bar,b::bar) is weird since bar is concrete, but strictly speaking its not wrong, hence I believe this is a bug.

A weird workaround is to put instead,

immutable bar{T<:Real} <: foo{T} end

which is redundant since subtyping foo{T} should guarantee T<:Real anyway, but nevertheless this seems to fix the problem.

Tested on:


julia> versioninfo()
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
  System: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, broadwell)

and

julia> versioninfo()
Julia Version 0.6.0-dev.2856
Commit 34b39f8* (2017-02-19 00:02 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)

in which case some of the syntax in my example is changed to reflect 0.6.

@yuyichao
Copy link
Contributor

This is not a bug. T<:bar has to be concrete type so the second one cannot match f(::bar{Int}, ::bar{Int32}).

@yuyichao
Copy link
Contributor

Note that this is actually the first example given in the paramatric method section in the doc http://docs.julialang.org/en/latest/manual/methods.html#Parametric-Methods-1 . Not sure if we have a coherent definition and implementation of the dispatch yet but with jb/subtypes we are getting much closer on that.

@marius311
Copy link
Contributor Author

Sorry, I don't understand the explanation why this isn't a bug. What do you mean "T<:bar has to be concrete type" ?

@yuyichao
Copy link
Contributor

And the fact that the "workaround" works is another bug #20056 (comment).

@yuyichao
Copy link
Contributor

What do you mean "T<:bar has to be concrete type" ?

I mean the T in the method with T<:bar has to be a concrete type or (isleaftype). See the document I linked.

@yuyichao
Copy link
Contributor

Sorry, actually I read the upper bound wrong, in that case it's a dup of #11597 and #20570

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

2 participants