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

Fix method ambiguities introduced by DataStructures.jl (when combined with Setfield.jl) #511

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tkf
Copy link
Contributor

@tkf tkf commented Jun 25, 2019

(This PR is more like an issue report but I wanted to attach a possible solution. I am open to alternative fixes if any.)

It seems that the combination of DataStructures and Setfield introduces some method ambiguities to Base.get. They are between get(::DictType_from_DataStructures.jl, ...) and get(obj, ::Setfield.Lens). I'm posting the issue here because I think it's easier to fix in DataStructures.jl. (cc @jw3126)

You can invoke the ambiguity by, for example

julia> using Setfield, DataStructures

julia> get(MultiDict(:a=>[1]), @lens _[:a])
ERROR: MethodError: get(::MultiDict{Symbol,Int64}, ::Setfield.IndexLens{Tuple{Symbol}}) is ambiguous. Candidates:
  get(obj, l::Setfield.IndexLens) in Setfield at /home/takafumi/.julia/dev/Setfield/src/lens.jl:224
  get(a::MultiDict, args...) in DataStructures at /home/takafumi/.julia/packages/DataStructures/6r6kb/src/delegate.jl:21
Possible fix, define
  get(::MultiDict, ::Setfield.IndexLens)

I think the problem is that the @delegate macro declares the ownership of too many method signatures. It can be fixed by only delegating the 3-arg get method. In this PR, I propose to do this by adding a mapping between the method name and the desired arity like this

const _arities = Dict(
:get => 3,
:get! => 3,
)

It's not the most elegant solution but it works and extensible (i.e., supporting a new method can be done by just adding a new entry to _arities).

@codecov
Copy link

codecov bot commented Jun 25, 2019

Codecov Report

Merging #511 into master will increase coverage by 3.74%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #511      +/-   ##
==========================================
+ Coverage   89.11%   92.86%   +3.74%     
==========================================
  Files          31       31              
  Lines        2408     2314      -94     
==========================================
+ Hits         2146     2149       +3     
+ Misses        262      165      -97
Impacted Files Coverage Δ
src/delegate.jl 92.59% <100%> (+0.92%) ⬆️
src/int_set.jl 100% <0%> (+0.79%) ⬆️
src/heaps/minmax_heap.jl 100% <0%> (+0.95%) ⬆️
src/multi_dict.jl 75% <0%> (+1.08%) ⬆️
src/mutable_list.jl 99.32% <0%> (+1.32%) ⬆️
src/list.jl 100% <0%> (+1.53%) ⬆️
src/disjoint_set.jl 98.07% <0%> (+1.85%) ⬆️
src/priorityqueue.jl 98.64% <0%> (+1.95%) ⬆️
src/deque.jl 98.55% <0%> (+2.09%) ⬆️
src/sorted_multi_dict.jl 83.33% <0%> (+3.68%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3529577...3f5c280. Read the comment docs.

@jw3126
Copy link

jw3126 commented Jun 25, 2019

Solutions on the Setfield side I can think of would be:

  • Rename get. But I fear there is no name, which is as good as get.
  • Switch the argument order of get (and set and modify for consistency) urghs

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

Successfully merging this pull request may close these issues.

2 participants