Skip to content

Commit

Permalink
Expand macros first in @!
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Aug 29, 2019
1 parent 994e66b commit da5a9aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ julia> @! y .= 2 .* y
```
"""
macro !(expr)
foldexpr(expr) do x
foldexpr(macroexpand(__module__, expr)) do x
if Meta.isexpr(x, :call)
isdotoperator(x.args[1]) && return x
return Expr(:call, Expr(:call, _maybb, x.args[1]), x.args[2:end]...)
Expand Down
25 changes: 25 additions & 0 deletions test/test_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,29 @@ end
end
end

@testset "@." begin
@test !@isdefined y
@test begin
x = SVector(1, 2)
@! @. y = x * 2
end === SVector(2, 4)

@test !@isdefined y
@test begin
x = SVector(1, 2)
y = SVector(0, 0)
@! @. y = x * 2
end === SVector(2, 4)

let x = [1, 2]
y = [0, 0]
@test (@! @. y = x * 2)::Vector{Int} == [2, 4]
end

let x = [1, 2]
y = SVector(0, 0)
@test (@! @. y = x * 2)::Vector{Int} == [2, 4]
end
end

end # module

0 comments on commit da5a9aa

Please sign in to comment.