Skip to content

false ambiguity detection? #20995

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

Closed
Sacha0 opened this issue Mar 12, 2017 · 6 comments
Closed

false ambiguity detection? #20995

Sacha0 opened this issue Mar 12, 2017 · 6 comments
Labels
test This change adds or pertains to unit tests types and dispatch Types, subtyping and method dispatch

Comments

@Sacha0
Copy link
Member

Sacha0 commented Mar 12, 2017

Reduced from #20970,

julia> versioninfo()
Julia Version 0.6.0-pre.alpha.126
Commit 0615ea2 (2017-03-12 13:00 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)

julia> begin
           bar(x::AbstractMatrix{T}, y::Vector{Complex{T}}) where T<:Float64 = 1
           bar(x::Matrix{T}, y::Vector) where T<:Float64 = 2
           bar(x::Matrix{Float64}, y::Vector{Complex{Float64}}) = 3

           for (ma, mb) in Test.detect_ambiguities(Main; imported = true, allow_bottom = false)
               println("ma: ", ma)
               println("mb: ", mb)
               println("=> ", typeintersect(ma.sig, mb.sig))
           end
       end
ma: bar(x::AbstractArray{T,2}, y::Array{Complex{T},1}) where T<:Float64 in Main at REPL[3]:2
mb: bar(x::Array{T,2}, y::Array{T,1} where T) where T<:Float64 in Main at REPL[3]:3
=> Tuple{#bar,Array{T,2},Array{Complex{T},1}} where T<:Float64

julia> bar(rand(4, 4), complex.(rand(4), rand(4)))
3

julia> bar(x::Matrix{T}, y::Vector{Complex{T}}) where T<:Float64 = 4
bar (generic function with 4 methods)

julia> for (ma, mb) in Test.detect_ambiguities(Main; imported = true, allow_bottom = false)
           println("ma: ", ma)
           println("mb: ", mb)
           println("=> ", typeintersect(ma.sig, mb.sig))
       end

julia> bar(rand(4, 4), complex.(rand(4), rand(4)))
3

Best!

@Sacha0 Sacha0 added test This change adds or pertains to unit tests types and dispatch Types, subtyping and method dispatch labels Mar 12, 2017
@yuyichao
Copy link
Contributor

Seems like a missing ambiguity error.

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 12, 2017

Seems like a missing ambiguity error.

How so? You mean the behavior after introducing the fourth bar definition?

@yuyichao
Copy link
Contributor

NVM, I think I was confused by allow_bottom and which behavior is false...........

@StefanKarpinski
Copy link
Member

That keyword argument should probably be called ambiguous_bottom::Bool where true means that bottom is ambiguous while false means that bottom is not considered ambiguous.

@timholy
Copy link
Member

timholy commented Mar 13, 2017

See an alternative proposal at the bottom of #20982 (comment). If people don't think it's too late to change this for 0.6...

@JeffBezanson
Copy link
Member

I believe this is correct behavior. The case bar(rand(4, 4), complex.(rand(4), rand(4))) is covered by the third method definition, which is not ambiguous. The case bar(Array{Union{},2}(0,0), Array{Complex{Union{}},1}(0)) however does fall in the ambiguity, and indeed gives an error, so I think we're good here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

5 participants