diff --git a/src/ArgCheck.jl b/src/ArgCheck.jl index a6a4b92..624a920 100644 --- a/src/ArgCheck.jl +++ b/src/ArgCheck.jl @@ -1,5 +1,6 @@ __precompile__() module ArgCheck +using Base.Meta export @argcheck """ @@ -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)) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index feb1ad2..ad44f31 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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