Skip to content

Commit

Permalink
Merge pull request #6912 from stuartarchibald/fix/6894
Browse files Browse the repository at this point in the history
Prevent use of varargs in closure calls.
  • Loading branch information
sklam committed Apr 9, 2021
2 parents aeea0d4 + 6a9bb9c commit 476d192
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions numba/core/inline_closurecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ def _get_callee_args(call_expr, callee, loc, func_ir):
"""
if call_expr.op == 'call':
args = list(call_expr.args)
if call_expr.vararg:
msg = "Calling a closure with *args is unsupported."
raise errors.UnsupportedError(msg, call_expr.loc)
elif call_expr.op == 'getattr':
args = [call_expr.value]
elif ir_utils.is_operator_or_getitem(call_expr):
Expand Down
17 changes: 15 additions & 2 deletions numba/tests/test_closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,28 @@ def inner2(f, x):
return inner2(inner, x)

def outer20(x):
#""" Test calling numpy in closure """
""" Test calling numpy in closure """
z = x + 1

def inner(x):
return x + numpy.cos(z)
return inner(x)

def outer21(x):
#""" Test calling numpy import as in closure """
""" Test calling numpy import as in closure """
z = x + 1

def inner(x):
return x + np.cos(z)
return inner(x)

def outer22():
"""Test to ensure that unsupported *args raises correctly"""
def bar(a, b):
pass
x = 1, 2
bar(*x)

# functions to test that are expected to pass
f = [outer1, outer2, outer5, outer6, outer7, outer8,
outer9, outer10, outer12, outer13, outer14,
Expand Down Expand Up @@ -425,6 +432,12 @@ def inner(x):
msg = "The use of yield in a closure is unsupported."
self.assertIn(msg, str(raises.exception))

with self.assertRaises(UnsupportedError) as raises:
cfunc = jit(nopython=True)(outer22)
cfunc()
msg = "Calling a closure with *args is unsupported."
self.assertIn(msg, str(raises.exception))


class TestObjmodeFallback(TestCase):
# These are all based on tests from real life issues where, predominantly,
Expand Down

0 comments on commit 476d192

Please sign in to comment.