Skip to content

Commit 8dc5c4f

Browse files
authored
Fix @~ a.b; more robust is_call and is_dotcall (#69)
1 parent b271ffc commit 8dc5c4f

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/lazymacro.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ Broadcast.broadcasted(::typeof(lazy), x) = LazyCast(x)
1313
Broadcast.materialize(x::LazyCast) = x.value
1414

1515

16-
is_call(ex::Expr) =
17-
ex.head == :call && !startswith(String(ex.args[1]), ".")
16+
is_call(ex) = isexpr(ex, :call) && !is_dotcall(ex)
1817

19-
is_dotcall(ex::Expr) =
20-
(ex.head == :. && ex.args[2].head === :tuple) ||
21-
(ex.head == :call && startswith(String(ex.args[1]), "."))
18+
is_dotcall(ex) =
19+
(isexpr(ex, :.) && isexpr(ex.args[2], :tuple)) ||
20+
(isexpr(ex, :call) && ex.args[1] isa Symbol && startswith(String(ex.args[1]), "."))
2221
# e.g., `f.(x, y, z)` or `x .+ y .+ z`
2322

2423
lazy_expr(x) = x

test/macrotests.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ testparams = [
6262
end
6363
end
6464

65+
struct CustomProperty end
66+
Base.getproperty(::CustomProperty, property::Symbol) = property
67+
Base.getproperty(::CustomProperty, property) = property
68+
69+
complex_number = 1 + 2im
70+
custom_property = CustomProperty()
71+
72+
expressions_block = quote
73+
complex_number.im # https://github.com/JuliaArrays/LazyArrays.jl/pull/69
74+
custom_property."property"
75+
end
76+
testparams = [
77+
("$(rmlines(ex))", ex) for ex in expressions_block.args if ex isa Expr
78+
]
79+
80+
@testset "@~ non-lazy" begin
81+
@testset "$label" for (label, ex) in testparams
82+
desired = @eval $ex
83+
actual = @eval @~ $ex
84+
@test actual === desired
85+
end
86+
end
87+
6588
@testset "@~ laziness" begin
6689
A = ones(1, 1)
6790
x = [1]

0 commit comments

Comments
 (0)