Skip to content

Commit ed199a6

Browse files
committed
Fix splitarg to correctly handle ::Int
1 parent 303ae2e commit ed199a6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ call) such as `x::Int=2` and returns `(arg_name, arg_type, default)`. `default`
225225
```
226226
"""
227227
function splitarg(arg_expr)
228-
split_var(arg) = (@capture(arg, name_::T_)) ? (name, T) : (arg, :Any)
228+
split_var(arg) =
229+
@match arg begin
230+
::T_ => (nothing, T)
231+
name_::T_ => (name, T)
232+
x_ => (arg, :Any)
233+
end
229234
if @capture(arg_expr, arg_ = default_)
230235
@assert default !== nothing "splitarg cannot handle `nothing` as a default. Use a quoted `nothing` if possible. (MacroTools#35)"
231236
return (split_var(arg)..., default)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ let
100100
@test splitarg(def_elts[:args][1])[3] === nothing
101101
@test map(splitarg, (:(f(a=2, x::Int=nothing, y))).args[2:end]) ==
102102
[(:a, :Any, 2), (:x, :Int, :nothing), (:y, :Any, nothing)]
103+
@test splitarg(:(::Int)) == (nothing, :Int, nothing)
103104
end
104105

105106
include("destruct.jl")

0 commit comments

Comments
 (0)