diff --git a/src/FixFunctionArgument.jl b/src/FixFunctionArgument.jl index 449f229..cc0d185 100644 --- a/src/FixFunctionArgument.jl +++ b/src/FixFunctionArgument.jl @@ -17,10 +17,17 @@ module FixFunctionArgument @noinline function throw_too_few_args() throw(ArgumentError("too few positional arguments given in call of a `Fix`")) end + @noinline function throw_not_int() + throw(ArgumentError("the type parameter `N` must be an `Int`")) + end @noinline function throw_not_positive() throw(ArgumentError("the type parameter `N` must be greater than zero")) end - @inline function check_positive(n::Int) + @inline function check_positive(n) + if !(n isa Int) + throw_not_int() + end + n = n::Int if n < 1 throw_not_positive() end diff --git a/test/runtests.jl b/test/runtests.jl index 57d1c9c..fc2f0ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,6 +13,16 @@ using Test end @testset "basic" begin @test sin(0.3) === @inferred Fix1(sin, 0.3)() + @test (7 - 3) === @inferred Fix1(-, 7)(3) + @test (7 - 3) === @inferred Fix2(-, 3)(7) + end + @testset "invalid `N`" begin + for N ∈ (-1, 0, true) + @test_throws ArgumentError Fix{N}(+, 7) + end + end + @testset "too few arguments in call" begin + @test_throws ArgumentError Fix{10}(Returns(nothing), 7)(1, 2, 3) end end