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 bug in empty!, add tests for WeakKeyDict #19485

Merged
merged 1 commit into from
Dec 3, 2016
Merged

Fix bug in empty!, add tests for WeakKeyDict #19485

merged 1 commit into from
Dec 3, 2016

Conversation

kshyatt
Copy link
Contributor

@kshyatt kshyatt commented Dec 2, 2016

No description provided.

@kshyatt kshyatt added bugfix This change fixes an existing bug test This change adds or pertains to unit tests labels Dec 2, 2016
@@ -45,7 +45,7 @@ get!{K}(default::Callable, wkh::WeakKeyDict{K}, key) = lock(() -> get!(default,
pop!{K}(wkh::WeakKeyDict{K}, key) = lock(() -> pop!(wkh.ht, key), wkh)
pop!{K}(wkh::WeakKeyDict{K}, key, default) = lock(() -> pop!(wkh.ht, key, default), wkh)
delete!{K}(wkh::WeakKeyDict{K}, key) = lock(() -> delete!(wkh.ht, key), wkh)
empty!(wkh::WeakKeyDict) = (lock(() -> empty!(wkh.ht)); wkh)
empty!(wkh::WeakKeyDict) = lock(() -> empty!(wkh.ht), wkh)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle. What was the bug here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Got an exception of type MethodError outside of a @test
  MethodError: no method matching lock(::Base.##384#385{WeakKeyDict{Any,Any}})
  Closest candidates are:
    lock(::Any, !Matched::WeakKeyDict{K,V}) at weakkeydict.jl:21
    lock(::Any, !Matched::Any) at lock.jl:99
    lock(!Matched::Base.Threads.Mutex) at locks.jl:206
    ...
   in empty!; at ./weakkeydict.jl:48 [inlined]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this return wkd.ht now, instead of wkd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a test for that? We can see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's returning wkd.ht. Is there an easy way to fix that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps empty!(wkh::WeakKeyDict) = (lock(() -> empty!(wkh.ht), wkh); wkh)? Best!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That got it. Thanks, @Sacha0

@kshyatt
Copy link
Contributor Author

kshyatt commented Dec 3, 2016

CI (except for OSX) passed - OK to merge?

@vtjnash vtjnash merged commit 688d712 into master Dec 3, 2016
@vtjnash vtjnash deleted the ksh/wkd branch December 3, 2016 23:30
tkelman pushed a commit that referenced this pull request Mar 1, 2017
(cherry picked from commit 50f0848)
ref #19485

remove testset for release-0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants