Skip to content

Commit

Permalink
test for number of arguments edgecase
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jun 2, 2024
1 parent 3cb4133 commit 9867242
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ end

function (f::Fix{F,N,T})(args::Vararg{Any,M}) where {F,N,T,M}
@inline
M < N - 1 || throw(ArgumentError("expected at least $(N-1) arguments to a `Fix` function with `N=$(N)`"))
M < N - 1 || N == 1 || throw(ArgumentError("expected at least $(N-1) arguments to a `Fix` function with `N=$(N)`"))
return f.f(args[begin:begin+(N-2)]..., f.x..., args[begin+(N-1):end]...)
end

Expand Down
11 changes: 11 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ end
h = Fix(*, Val(1), "1", "2", "3")
@test h() == "123"
end
@testset "with integer rather than Val" begin
function f(x, y)
g = Fix(1, x, y) do x, y
x = x^2
y = y * 3.5
x + y
end
g()
end
@inferred f(1, 2)
end

@testset "varargs inside Fix" begin
lazy_sum = Fix(+, Val(1), 1, 2, 3, 4, 5)
Expand Down

0 comments on commit 9867242

Please sign in to comment.