Skip to content

Commit 7ae6e14

Browse files
committed
Simplify isdef() test
* Allows return types, where clauses
1 parent 0c626fc commit 7ae6e14

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/utils.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,7 @@ end
215215

216216

217217
"Test for function definition expressions."
218-
isdef(ex) = ismatch(or_(:(function _(__) _ end),
219-
:(function _(__)::_ _ end),
220-
:(f_(__) = _),
221-
:(f_(__)::_ = _)),
222-
ex)
218+
isdef(ex) = isshortdef(ex) || longdef1(ex) !== nothing
223219

224220
isshortdef(ex) = (@capture(ex, (fcall_ = body_)) &&
225221
(@capture(gatherwheres(fcall)[1],

test/utils.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ using MacroTools: isdef
55
@test isdef(ex1)
66
ex2 = :(function bar(a)::Int return 1; end)
77
@test isdef(ex2)
8-
ex3 = :(f(a) = a)
8+
ex3 = :(function foo(a::T) where T return a; end)
99
@test isdef(ex3)
10-
ex4 = :(f(a)::Int = 1)
10+
ex4 = :(function bar(a::T)::Int where T return 1; end)
1111
@test isdef(ex4)
12+
ex5 = :(function bar(a::S, b::T)::Union{S,T} where {S,T} if rand() < 0.5 return a; end; return b; end)
13+
@test isdef(ex5)
14+
15+
ex6 = :(f(a) = a)
16+
@test isdef(ex6)
17+
ex7 = :(f(a)::Int == 1)
18+
@test isdef(ex7)
19+
ex8 = :(f(a::T) where T = a)
20+
@test isdef(ex8)
21+
ex9 = :(f(a::T)::Int where T = 1)
22+
@test isdef(ex9)
23+
ex10 = :(f(a::S, b::T)::Union{S,T} where {S,T} = rand() < 0.5 ? a : b)
24+
@test isdef(ex10)
1225
end

0 commit comments

Comments
 (0)