I’m updating the SortedSet
constructors in DataStructures.jl
, and I’m having trouble removing a particular ambiguity warning from Julia v0.4. The code works fine in v0.5 and v0.6 (and not just because ambiguity warnings were moved to runtime).
The warning stems from
SortedSet{O<:Ordering}(o::O, iter) = sortedset_with_eltype(o, iter, eltype(iter))
SortedSet{O<:Ordering}(iter, o::O) = sortedset_with_eltype(o, iter, eltype(iter))
This makes sense–if one calls this constructor with two Ordering
s, the call is ambiguous (even if this unlikely to happen).
The actual warning, however, is
WARNING: New definition
call(Type{DataStructures.SortedSet}, Any, #O<:Base.Order.Ordering) at /Users/kevin/.julia/v0.4/DataStructures/src/sorted_set.jl:30
is ambiguous with:
call(Type{DataStructures.SortedSet}, #O<:Base.Order.Ordering, Any) at /Users/kevin/.julia/v0.4/DataStructures/src/sorted_set.jl:29.
To fix, define
call(Type{DataStructures.SortedSet}, _<:Any, _<:Any)
before the new definition.
The warning itself is slightly unclear (I’m pretty sure _
is a type variable), but I believe either of the following definitions should handle the actual ambiguity:
SortedSet(::Ordering,::Ordering) = throw(ArgumentError("SortedSet with two parameters must be called with an Ordering and an interable"))
SortedSet{T}(::T,::T) = throw(ArgumentError("SortedSet with two parameters must be called with an Ordering and an interable"))
Unfortunately, neither does. Am I missing something, or is this an issue with the parser in v0.4?
With v0.6 around the corner, this arguably isn’t that important. But there’s a desire to continue to support DataStructures.jl on v0.4, so it would be nice not to introduce this warning.
Any thoughts welcome!
Cheers,
Kevin