Skip to content

Commit 476d192

Browse files
authored
Merge pull request #6912 from stuartarchibald/fix/6894
Prevent use of varargs in closure calls.
2 parents aeea0d4 + 6a9bb9c commit 476d192

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎numba/core/inline_closurecall.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ def _get_callee_args(call_expr, callee, loc, func_ir):
696696
"""
697697
if call_expr.op == 'call':
698698
args = list(call_expr.args)
699+
if call_expr.vararg:
700+
msg = "Calling a closure with *args is unsupported."
701+
raise errors.UnsupportedError(msg, call_expr.loc)
699702
elif call_expr.op == 'getattr':
700703
args = [call_expr.value]
701704
elif ir_utils.is_operator_or_getitem(call_expr):

‎numba/tests/test_closure.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,28 @@ def inner2(f, x):
364364
return inner2(inner, x)
365365

366366
def outer20(x):
367-
#""" Test calling numpy in closure """
367+
""" Test calling numpy in closure """
368368
z = x + 1
369369

370370
def inner(x):
371371
return x + numpy.cos(z)
372372
return inner(x)
373373

374374
def outer21(x):
375-
#""" Test calling numpy import as in closure """
375+
""" Test calling numpy import as in closure """
376376
z = x + 1
377377

378378
def inner(x):
379379
return x + np.cos(z)
380380
return inner(x)
381381

382+
def outer22():
383+
"""Test to ensure that unsupported *args raises correctly"""
384+
def bar(a, b):
385+
pass
386+
x = 1, 2
387+
bar(*x)
388+
382389
# functions to test that are expected to pass
383390
f = [outer1, outer2, outer5, outer6, outer7, outer8,
384391
outer9, outer10, outer12, outer13, outer14,
@@ -425,6 +432,12 @@ def inner(x):
425432
msg = "The use of yield in a closure is unsupported."
426433
self.assertIn(msg, str(raises.exception))
427434

435+
with self.assertRaises(UnsupportedError) as raises:
436+
cfunc = jit(nopython=True)(outer22)
437+
cfunc()
438+
msg = "Calling a closure with *args is unsupported."
439+
self.assertIn(msg, str(raises.exception))
440+
428441

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

0 commit comments

Comments
 (0)