Skip to content

Commit e379499

Browse files
szcf-weiyastevengj
andauthored
fix BoundsError of args[1] when args is empty (#1014)
* fix BoundsError of args[1] when args is empty if `args` on L101 is empty, then `args[1]` in `isexpr()` would throw `BoundsError: attempt to access 0-element Vector{Any} at index [1]` * add unit tests for empty arguments * Update src/pyfncall.jl * Update src/pyfncall.jl Co-authored-by: Steven G. Johnson <[email protected]>
1 parent 3b0a0f4 commit e379499

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/pyfncall.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ macro pycall(ex)
9999
end
100100
func = ex.args[1].args[1]
101101
args, kwargs = ex.args[1].args[2:end], []
102-
if isexpr(args[1],:parameters)
102+
if !isempty(args) && isexpr(args[1],:parameters)
103103
kwargs, args = args[1], args[2:end]
104104
end
105105
T = ex.args[2]

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ const PyInt = pyversion < v"3" ? Int : Clonglong
530530

531531
# @pycall macro expands correctly
532532
_pycall = GlobalRef(PyCall,:pycall)
533+
@test macroexpand(@__MODULE__, :(@pycall foo()::T)) == :($(_pycall)(foo, T))
534+
@test macroexpand(@__MODULE__, :(@pycall foo(; kwargs...)::T)) == :($(_pycall)(foo, T; kwargs...))
533535
@test macroexpand(@__MODULE__, :(@pycall foo(bar)::T)) == :($(_pycall)(foo, T, bar))
534536
@test macroexpand(@__MODULE__, :(@pycall foo(bar, args...)::T)) == :($(_pycall)(foo, T, bar, args...))
535537
@test macroexpand(@__MODULE__, :(@pycall foo(bar; kwargs...)::T)) == :($(_pycall)(foo, T, bar; kwargs...))

0 commit comments

Comments
 (0)