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 error with non-applicable methods #31993

Closed
rfourquet opened this issue May 10, 2019 · 3 comments · Fixed by #31997
Closed

ambiguity error with non-applicable methods #31993

rfourquet opened this issue May 10, 2019 · 3 comments · Fixed by #31997
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@rfourquet
Copy link
Member

julia> g(::Type{<:AbstractVector{T}}, ::Int) where {T} = 1

julia> g(Vector, 1)
ERROR: MethodError: no method matching g(::Type{Array{T,1} where T}, ::Int64)
Closest candidates are:
  g(::Type{#s1} where #s1<:AbstractArray{T,1}, ::Int64) where T at REPL[1]:1
Stacktrace:
 [1] top-level scope at REPL[2]:1

julia> g(::Type{Vector}, ::Any) = 2

julia> g(Vector, 1)
ERROR: MethodError: g(::Type{Array{T,1} where T}, ::Int64) is ambiguous. Candidates:
  g(::Type{#s1} where #s1<:AbstractArray{T,1}, ::Int64) where T in Main at REPL[1]:1
  g(::Type{Array{T,1} where T}, ::Any) in Main at REPL[3]:1
Possible fix, define
  g(::Type{Array{T,1} where T}, ::Int64)
Stacktrace:
 [1] top-level scope at REPL[4]:1

julia> f() = g(Vector, 1); f() # works on Julia 1.1 ! But errors on master
2

The last line with f is the reason why tests in my package where passing on 1.1 but not on master.

@rfourquet rfourquet added bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch labels May 10, 2019
@Keno
Copy link
Member

Keno commented May 10, 2019

The error on master is a bugfix, so it probably doesn't count a regression (just that one bug canceled out another). @JeffBezanson will have to judge the type system issue.

@rfourquet
Copy link
Member Author

Yes agreed that it's not a regression, I inserted the example with f just as contextual information.

@JeffBezanson
Copy link
Member

Type intersection used to give exactly the first signature as its result, even though they should be disjoint. Now it gives Type{Vector}, Int which is not really better or worse, but doesn't equal either signature hence the ambiguity.

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 types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants