From 7747bd53653083d1124fe2d1ba3745771df7bba2 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 6 Aug 2018 20:07:21 -0400 Subject: [PATCH] Make broadcasting over sets an error --- base/broadcast.jl | 1 + test/broadcast.jl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/base/broadcast.jl b/base/broadcast.jl index 3e826c5fc7fb3..755cc3d0a8401 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -608,6 +608,7 @@ broadcastable(x::Union{AbstractArray,Number,Ref,Tuple,Broadcasted}) = x # Default to collecting iterables — which will error for non-iterables broadcastable(x) = collect(x) broadcastable(::Union{AbstractDict, NamedTuple}) = throw(ArgumentError("broadcasting over dictionaries and `NamedTuple`s is reserved")) +broadcastable(::AbstractSet) = throw(ArgumentError("broadcasting over sets is not defined as their order is not defined")) ## Computation of inferred result type, for empty and concretely inferred cases only _broadcast_getindex_eltype(bc::Broadcasted) = Base._return_type(bc.f, eltypes(bc.args)) diff --git a/test/broadcast.jl b/test/broadcast.jl index 8225f873952f0..aaab3b61c99a3 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -599,8 +599,8 @@ end @test broadcast(identity, Iterators.filter(iseven, 1:10)) == 2:2:10 d = Dict([1,2] => 1.1, [3,2] => 0.1) - @test length.(keys(d)) == [2,2] - @test Set(exp.(Set([1,2,3]))) == Set(exp.([1,2,3])) + @test_broken length.(keys(d)) == [2,2] # Issue #20678 + @test_throws ArgumentError Set(exp.(Set([1,2,3]))) == Set(exp.([1,2,3])) end # Test that broadcasting identity where the input and output Array shapes do not match