Skip to content

Commit df01d34

Browse files
committed
fix error check in WeakKeyDict constructor
1 parent a1f232e commit df01d34

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/weakkeydict.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ function WeakKeyDict(kv)
5555
try
5656
Base.associative_with_eltype((K, V) -> WeakKeyDict{K, V}, kv, eltype(kv))
5757
catch e
58-
if any(x->isempty(methods(x, (typeof(kv),))), [start, next, done]) ||
59-
!all(x->isa(x,Union{Tuple,Pair}),kv)
58+
if !applicable(start, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv)
6059
throw(ArgumentError("WeakKeyDict(kv): kv needs to be an iterator of tuples or pairs"))
6160
else
6261
rethrow(e)

test/dict.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ d = Dict(:a=>"a")
443443
@test_throws ArgumentError Dict([1])
444444
@test_throws ArgumentError Dict([(1,2),0])
445445

446+
# test Dict constructor's argument checking (for an iterable of pairs or tuples)
447+
# make sure other errors can propagate when the nature of the iterator is not the problem
448+
@test_throws InexactError Dict(convert(Int,1.5) for i=1:1)
449+
@test_throws InexactError WeakKeyDict(convert(Int,1.5) for i=1:1)
450+
446451
# ImmutableDict
447452
import Base.ImmutableDict
448453
let d = ImmutableDict{String, String}(),

0 commit comments

Comments
 (0)