Skip to content

Commit 0c626fc

Browse files
committed
Allow isdef() to match functions with return types
1 parent 4af2b1a commit 0c626fc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ end
216216

217217
"Test for function definition expressions."
218218
isdef(ex) = ismatch(or_(:(function _(__) _ end),
219-
:(f_(__) = _)),
219+
:(function _(__)::_ _ end),
220+
:(f_(__) = _),
221+
:(f_(__)::_ = _)),
220222
ex)
221223

222224
isshortdef(ex) = (@capture(ex, (fcall_ = body_)) &&

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ using Test
66
include("match.jl")
77
include("split.jl")
88
include("destruct.jl")
9+
include("utils.jl")
910

1011
end

test/utils.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using MacroTools: isdef
2+
3+
@testset "utils" begin
4+
ex1 = :(function foo(a) return a; end)
5+
@test isdef(ex1)
6+
ex2 = :(function bar(a)::Int return 1; end)
7+
@test isdef(ex2)
8+
ex3 = :(f(a) = a)
9+
@test isdef(ex3)
10+
ex4 = :(f(a)::Int = 1)
11+
@test isdef(ex4)
12+
end

0 commit comments

Comments
 (0)