Skip to content

Commit

Permalink
fix inconsistent BroadcastFunction behavior (#40330)
Browse files Browse the repository at this point in the history
fixes #40309
  • Loading branch information
simeonschaub authored Apr 3, 2021
1 parent 595b0e6 commit b0b4a48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,13 @@ macro __dot__(x)
esc(__dot__(x))
end

@inline broadcasted_kwsyntax(f, args...; kwargs...) = broadcasted((args...)->f(args...; kwargs...), args...)
@inline function broadcasted_kwsyntax(f, args...; kwargs...)
if isempty(kwargs) # some BroadcastStyles dispatch on `f`, so try to preserve its type
return broadcasted(f, args...)
else
return broadcasted((args...) -> f(args...; kwargs...), args...)
end
end
@inline function broadcasted(f, args...)
args′ = map(broadcastable, args)
broadcasted(combine_styles(args′...), f, args′...)
Expand Down
4 changes: 4 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1015,3 +1015,7 @@ end
@test a_ == dropdims(a .* c, dims=(findall(==(1), size(c))...,))
end
end

# issue 40309
@test Base.broadcasted_kwsyntax(+, [1], [2]) isa Broadcast.Broadcasted{<:Any, <:Any, typeof(+)}
@test Broadcast.BroadcastFunction(+)(2:3, 2:3) === 4:2:6

0 comments on commit b0b4a48

Please sign in to comment.