Skip to content

Commit

Permalink
fix error with keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Nov 4, 2017
1 parent 3740f21 commit c891d07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/ArgCheck.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__precompile__()
module ArgCheck
using Base.Meta
export @argcheck

"""
Expand All @@ -22,17 +23,24 @@ end

function argcheck(ex, args...)
ex = canonicalize(ex)
if !isa(ex, Expr)
argcheck_fallback(ex, args...)
elseif ex.head == :comparison
if isexpr(ex, :comparison)
argcheck_comparison(ex, args...)
elseif ex.head == :call
elseif is_simple_call(ex)
argcheck_call(ex, args...)
else
argcheck_fallback(ex, args...)
end
end

function is_simple_call(ex)
isexpr(ex, :call) || return false
for arg in ex.args
isexpr(arg,:parameters) && return false
isexpr(arg,:kw) && return false
end
true
end

function argcheck_fallback(ex, args...)
quote
if !$(esc(ex))
Expand Down Expand Up @@ -133,8 +141,8 @@ function fancy_error_message(code, exprs, values)
join(lines, '\n')
end

function is_comparison_call(ex::Expr)
ex.head == :call &&
function is_comparison_call(ex)
isexpr(ex, :call) &&
length(ex.args) == 3 &&
is_comparison_op(ex.args[1])
end
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ end
@test contains(msg, "fail_function")
end

@testset "keyword arguments" begin
@argcheck issorted([2,1], rev=true)
@argcheck issorted([2,1]; rev=true)
end

@testset "deprecate" begin

# deprecate
Expand Down

0 comments on commit c891d07

Please sign in to comment.