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

Ambiguity warning: false positive? #10174

Closed
amartgon opened this issue Feb 12, 2015 · 8 comments
Closed

Ambiguity warning: false positive? #10174

amartgon opened this issue Feb 12, 2015 · 8 comments
Assignees
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@amartgon
Copy link

In the example bellow I get this warning, even though it seems to me that the two methods are not ambiguous. Am I missing something or is the compiler?

myf(x::SparseMatrixCSC, y::SparseMatrixCSC...) = 0
myf(x::Any, y::Array...) = 1

#OUTPUT:

#Warning: New definition
#    myf(Any,Array{T,N}...) at /tmp/test.jl:6
#is ambiguous with:
#    myf(Base.SparseMatrix.SparseMatrixCSC{Tv,Ti<:Integer},Base.SparseMatrix.SparseMatrixCSC{Tv,Ti<:Integer}...) at /tmp/test.jl:5.
#To fix, define
#    myf(Base.SparseMatrix.SparseMatrixCSC{Tv,Ti<:Integer},)
#before the new definition.
@JeffBezanson
Copy link
Sponsor Member

You're right, the warning does not look necessary.

@JeffBezanson JeffBezanson self-assigned this Mar 7, 2015
@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Mar 7, 2015
@yuyichao
Copy link
Contributor

I think this ambiguity is real? None of the two definitions seems to be more specific than the other one.

@toivoh
Copy link
Contributor

toivoh commented Mar 10, 2016 via email

@timholy
Copy link
Sponsor Member

timholy commented May 8, 2016

Still a problem on current master.

@yuyichao
Copy link
Contributor

yuyichao commented May 8, 2016

What's the problem?

@timholy
Copy link
Sponsor Member

timholy commented May 8, 2016

Only one case:

julia> S = sprand(3,3,0.4)
3×3 sparse matrix with 3 Float64 nonzero entries:
        [1, 1]  =  0.470274
        [3, 2]  =  0.0942641
        [3, 3]  =  0.214061

julia> @test myf(S) == 0
Error During Test
  Test threw an exception of type MethodError
  Expression: myf(S) == 0
  MethodError: myf(::SparseMatrixCSC{Float64,Int64}) is ambiguous. Candidates:
    svec(Tuple{#myf,SparseMatrixCSC{Float64,Int64}},svec(),myf(x, y::Array...) at REPL[16]:1)
    svec(Tuple{#myf,SparseMatrixCSC{Float64,Int64}},svec(),myf(x::SparseMatrixCSC, y::SparseMatrixCSC...) at REPL[15]:2)
   in eval(::Module, ::Any) at ./boot.jl:230
ERROR: There was an error during testing
 in record(::Base.Test.FallbackTestSet, ::Base.Test.Error) at ./test.jl:321
 in do_test(::Base.Test.Threw, ::Expr) at ./test.jl:219
 in eval(::Module, ::Any) at ./boot.jl:230

julia> @test myf(S, S) == 0
Test Passed
  Expression: myf(S,S) == 0
   Evaluated: 0 == 0

julia> @test myf("foo") == 1
Test Passed
  Expression: myf("foo") == 1
   Evaluated: 1 == 1

julia> @test myf("foo", zeros(2,2)) == 1
Test Passed
  Expression: myf("foo",zeros(2,2)) == 1
   Evaluated: 1 == 1

julia> @test myf(S, zeros(2,2)) == 1
Test Passed
  Expression: myf(S,zeros(2,2)) == 1
   Evaluated: 1 == 1

@yuyichao
Copy link
Contributor

yuyichao commented May 8, 2016

I guess I still think this is indeed ambiguous... not sure which way is better....

@JeffBezanson
Copy link
Sponsor Member

JeffBezanson commented Jun 1, 2017

Fixed in 0.6. These aren't ambiguous --- the overlap is myf(x::SparseMatrixCSC), for which the first definition is obviously more specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

5 participants