-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
CI (except for OSX) passed - OK to merge? |
No description provided.