Skip to content

Commit f59ed8a

Browse files
committed
fix broadcast calls
1 parent df7fd77 commit f59ed8a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/JuliaVariables.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ is_broadcast_fusing(sym) = begin
139139
endswith(s, "=") && startswith(s, ".")
140140
end
141141

142+
is_broadcast_sym(sym) = begin
143+
s = string(sym)
144+
startswith(s, ".") && Base.isoperator(Symbol(s[1:end]))
145+
end
146+
142147
is_rhs_sym(sym) = begin
143148
(sym in Symbol[:ref, :.])
144149
end
@@ -312,6 +317,15 @@ function solve(ana, ex, ctx_flag::CtxFlag = CtxFlag())
312317
end
313318
Expr(:tuple, args...)
314319
end
320+
# keyword arguments for tuples or calls
321+
Expr(:kw, k::Symbol, v) => Expr(:kw, k, solve(ana, v, ctx_flag + :rhs))
322+
# broadcasting symbols
323+
Expr(:call, f :: Symbol, args...) &&
324+
if length(args) in (1, 2) && is_broadcast_sym(f)
325+
end =>
326+
@quick_lambda let args = map(solve(ana, _, ctx_flag), args)
327+
Expr(:call, f, args...)
328+
end
315329
Expr(hd, args...) =>
316330
@quick_lambda begin
317331
if is_rhs_sym(hd)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,9 @@ JuliaVariables.@quick_lambda begin
5858
end
5959
))
6060
@test haskey(a.scope.bounds, :T)
61+
62+
63+
a = solve(:(2 .^ [2, 3]))
64+
@test eval(a) == [4, 8]
6165
end
6266
end

0 commit comments

Comments
 (0)