Repository: numba/numba

Issue:
possible regression in typing
## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
  visible in the release notes
  (https://numba.readthedocs.io/en/stable/release-notes-overview.html).
- [x] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

The following code raise errors with numba 0.60 but works fine with 0.59

```python
from numba.typed import List
from numba import njit, objmode, f8

@njit
def f(a, b):
    return a + b

@njit
def wrapped(x):
    if isinstance(x, List):
        with objmode(res=f8):
            res = f(*x)
        return res
    else:
        return f(x)

wrapped(List([1,2]))
```
```python
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 wrapped(List([1,2]))

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:442, in _DispatcherBase._compile_for_args(self, *args, **kws)
    440             e.patch_message('\n'.join((str(e).rstrip(), help_msg)))
    441     # ignore the FULL_TRACEBACKS config, this needs reporting!
--> 442     raise e
    443 finally:
    444     self._types_active_call = []

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:375, in _DispatcherBase._compile_for_args(self, *args, **kws)
    373 return_val = None
    374 try:
--> 375     return_val = self.compile(tuple(argtypes))
    376 except errors.ForceLiteralArg as e:
    377     # Received request for compiler re-entry with the list of arguments
    378     # indicated by e.requested_args.
    379     # First, check if any of these args are already Literal-ized
    380     already_lit_pos = [i for i in e.requested_args
    381                        if isinstance(args[i], types.Literal)]

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:905, in Dispatcher.compile(self, sig)
    903 with ev.trigger_event("numba:compile", data=ev_details):
    904     try:
--> 905         cres = self._compiler.compile(args, return_type)
    906     except errors.ForceLiteralArg as e:
    907         def folded(args, kws):

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:80, in _FunctionCompiler.compile(self, args, return_type)
     79 def compile(self, args, return_type):
---> 80     status, retval = self._compile_cached(args, return_type)
     81     if status:
     82         return retval

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:94, in _FunctionCompiler._compile_cached(self, args, return_type)
     91     pass
     93 try:
---> 94     retval = self._compile_core(args, return_type)
     95 except errors.TypingError as e:
     96     self._failed_cache[key] = e

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:107, in _FunctionCompiler._compile_core(self, args, return_type)
    104 flags = self._customize_flags(flags)
    106 impl = self._get_implementation(args, {})
--> 107 cres = compiler.compile_extra(self.targetdescr.typing_context,
    108                               self.targetdescr.target_context,
    109                               impl,
    110                               args=args, return_type=return_type,
    111                               flags=flags, locals=self.locals,
    112                               pipeline_class=self.pipeline_class)
    113 # Check typing error if object mode is used
    114 if cres.typing_error is not None and not flags.enable_pyobject:

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:744, in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
    720 """Compiler entry point
    721 
    722 Parameter
   (...)
    740     compiler pipeline
    741 """
    742 pipeline = pipeline_class(typingctx, targetctx, library,
    743                           args, return_type, flags, locals)
--> 744 return pipeline.compile_extra(func)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:438, in CompilerBase.compile_extra(self, func)
    436 self.state.lifted = ()
    437 self.state.lifted_from = None
--> 438 return self._compile_bytecode()

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:506, in CompilerBase._compile_bytecode(self)
    502 """
    503 Populate and run pipeline for bytecode input
    504 """
    505 assert self.state.func_ir is None
--> 506 return self._compile_core()

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:481, in CompilerBase._compile_core(self)
    478 except Exception as e:
    479     if (utils.use_new_style_errors() and not
    480             isinstance(e, errors.NumbaError)):
--> 481         raise e
    483     self.state.status.fail_reason = e
    484     if is_final_pipeline:

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:472, in CompilerBase._compile_core(self)
    470 res = None
    471 try:
--> 472     pm.run(self.state)
    473     if self.state.cr is not None:
    474         break

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:364, in PassManager.run(self, state)
    361 except Exception as e:
    362     if (utils.use_new_style_errors() and not
    363             isinstance(e, errors.NumbaError)):
--> 364         raise e
    365     msg = "Failed in %s mode pipeline (step: %s)" % \
    366         (self.pipeline_name, pass_desc)
    367     patched_exception = self._patch_error(msg, e)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
    354 pass_inst = _pass_registry.get(pss).pass_inst
    355 if isinstance(pass_inst, CompilerPass):
--> 356     self._runPass(idx, pass_inst, state)
    357 else:
    358     raise BaseException("Legacy pass in use")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
     32 @functools.wraps(func)
     33 def _acquire_compile_lock(*args, **kwargs):
     34     with self:
---> 35         return func(*args, **kwargs)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
    309     mutated |= check(pss.run_initialization, internal_state)
    310 with SimpleTimer() as pass_time:
--> 311     mutated |= check(pss.run_pass, internal_state)
    312 with SimpleTimer() as finalize_time:
    313     mutated |= check(pss.run_finalizer, internal_state)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass.<locals>.check(func, compiler_state)
    272 def check(func, compiler_state):
--> 273     mangled = func(compiler_state)
    274     if mangled not in (True, False):
    275         msg = ("CompilerPass implementations should return True/False. "
    276                "CompilerPass with name '%s' did not.")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/untyped_passes.py:278, in WithLifting.run_pass(self, state)
    276 if withs:
    277     from numba.core.compiler import compile_ir, _EarlyPipelineCompletion
--> 278     cres = compile_ir(state.typingctx, state.targetctx, main,
    279                       state.args, state.return_type,
    280                       state.flags, state.locals,
    281                       lifted=tuple(withs), lifted_from=None,
    282                       pipeline_class=type(state.pipeline))
    283     raise _EarlyPipelineCompletion(cres)
    284 return True

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:807, in compile_ir(typingctx, targetctx, func_ir, args, return_type, flags, locals, lifted, lifted_from, is_lifted_loop, library, pipeline_class)
    804 else:
    805     pipeline = pipeline_class(typingctx, targetctx, library,
    806                               args, return_type, flags, locals)
--> 807     return pipeline.compile_ir(func_ir=func_ir, lifted=lifted,
    808                                lifted_from=lifted_from)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:448, in CompilerBase.compile_ir(self, func_ir, lifted, lifted_from)
    445 self.state.nargs = self.state.func_ir.arg_count
    447 FixupArgs().run_pass(self.state)
--> 448 return self._compile_ir()

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:513, in CompilerBase._compile_ir(self)
    509 """
    510 Populate and run pipeline for IR input
    511 """
    512 assert self.state.func_ir is not None
--> 513 return self._compile_core()

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:481, in CompilerBase._compile_core(self)
    478 except Exception as e:
    479     if (utils.use_new_style_errors() and not
    480             isinstance(e, errors.NumbaError)):
--> 481         raise e
    483     self.state.status.fail_reason = e
    484     if is_final_pipeline:

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler.py:472, in CompilerBase._compile_core(self)
    470 res = None
    471 try:
--> 472     pm.run(self.state)
    473     if self.state.cr is not None:
    474         break

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:364, in PassManager.run(self, state)
    361 except Exception as e:
    362     if (utils.use_new_style_errors() and not
    363             isinstance(e, errors.NumbaError)):
--> 364         raise e
    365     msg = "Failed in %s mode pipeline (step: %s)" % \
    366         (self.pipeline_name, pass_desc)
    367     patched_exception = self._patch_error(msg, e)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
    354 pass_inst = _pass_registry.get(pss).pass_inst
    355 if isinstance(pass_inst, CompilerPass):
--> 356     self._runPass(idx, pass_inst, state)
    357 else:
    358     raise BaseException("Legacy pass in use")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
     32 @functools.wraps(func)
     33 def _acquire_compile_lock(*args, **kwargs):
     34     with self:
---> 35         return func(*args, **kwargs)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
    309     mutated |= check(pss.run_initialization, internal_state)
    310 with SimpleTimer() as pass_time:
--> 311     mutated |= check(pss.run_pass, internal_state)
    312 with SimpleTimer() as finalize_time:
    313     mutated |= check(pss.run_finalizer, internal_state)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass.<locals>.check(func, compiler_state)
    272 def check(func, compiler_state):
--> 273     mangled = func(compiler_state)
    274     if mangled not in (True, False):
    275         msg = ("CompilerPass implementations should return True/False. "
    276                "CompilerPass with name '%s' did not.")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/untyped_passes.py:1677, in LiteralPropagationSubPipelinePass.run_pass(self, state)
   1674 pm.add_pass(DeadBranchPrune, "dead branch pruning")
   1676 pm.finalize()
-> 1677 pm.run(state)
   1678 return True

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:364, in PassManager.run(self, state)
    361 except Exception as e:
    362     if (utils.use_new_style_errors() and not
    363             isinstance(e, errors.NumbaError)):
--> 364         raise e
    365     msg = "Failed in %s mode pipeline (step: %s)" % \
    366         (self.pipeline_name, pass_desc)
    367     patched_exception = self._patch_error(msg, e)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
    354 pass_inst = _pass_registry.get(pss).pass_inst
    355 if isinstance(pass_inst, CompilerPass):
--> 356     self._runPass(idx, pass_inst, state)
    357 else:
    358     raise BaseException("Legacy pass in use")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
     32 @functools.wraps(func)
     33 def _acquire_compile_lock(*args, **kwargs):
     34     with self:
---> 35         return func(*args, **kwargs)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
    309     mutated |= check(pss.run_initialization, internal_state)
    310 with SimpleTimer() as pass_time:
--> 311     mutated |= check(pss.run_pass, internal_state)
    312 with SimpleTimer() as finalize_time:
    313     mutated |= check(pss.run_finalizer, internal_state)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass.<locals>.check(func, compiler_state)
    272 def check(func, compiler_state):
--> 273     mangled = func(compiler_state)
    274     if mangled not in (True, False):
    275         msg = ("CompilerPass implementations should return True/False. "
    276                "CompilerPass with name '%s' did not.")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typed_passes.py:112, in BaseTypeInference.run_pass(self, state)
    106 """
    107 Type inference and legalization
    108 """
    109 with fallback_context(state, 'Function "%s" failed type inference'
    110                       % (state.func_id.func_name,)):
    111     # Type inference
--> 112     typemap, return_type, calltypes, errs = type_inference_stage(
    113         state.typingctx,
    114         state.targetctx,
    115         state.func_ir,
    116         state.args,
    117         state.return_type,
    118         state.locals,
    119         raise_errors=self._raise_errors)
    120     state.typemap = typemap
    121     # save errors in case of partial typing

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typed_passes.py:93, in type_inference_stage(typingctx, targetctx, interp, args, return_type, locals, raise_errors)
     91     infer.build_constraint()
     92     # return errors in case of partial typing
---> 93     errs = infer.propagate(raise_errors=raise_errors)
     94     typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)
     96 return _TypingResults(typemap, restype, calltypes, errs)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:1083, in TypeInferer.propagate(self, raise_errors)
   1080 oldtoken = newtoken
   1081 # Errors can appear when the type set is incomplete; only
   1082 # raise them when there is no progress anymore.
-> 1083 errors = self.constraints.propagate(self)
   1084 newtoken = self.get_state_token()
   1085 self.debug.propagate_finished()

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:182, in ConstraintNetwork.propagate(self, typeinfer)
    180     errors.append(utils.chain_exception(new_exc, e))
    181 elif utils.use_new_style_errors():
--> 182     raise e
    183 else:
    184     msg = ("Unknown CAPTURED_ERRORS style: "
    185            f"'{config.CAPTURED_ERRORS}'.")

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:160, in ConstraintNetwork.propagate(self, typeinfer)
    157 with typeinfer.warnings.catch_warnings(filename=loc.filename,
    158                                        lineno=loc.line):
    159     try:
--> 160         constraint(typeinfer)
    161     except ForceLiteralArg as e:
    162         errors.append(e)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:583, in CallConstraint.__call__(self, typeinfer)
    581     fnty = typevars[self.func].getone()
    582 with new_error_context("resolving callee type: {0}", fnty):
--> 583     self.resolve(typeinfer, typevars, fnty)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:606, in CallConstraint.resolve(self, typeinfer, typevars, fnty)
    604     fnty = fnty.instance_type
    605 try:
--> 606     sig = typeinfer.resolve_call(fnty, pos_args, kw_args)
    607 except ForceLiteralArg as e:
    608     # Adjust for bound methods
    609     folding_args = ((fnty.this,) + tuple(self.args)
    610                     if isinstance(fnty, types.BoundFunction)
    611                     else self.args)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typeinfer.py:1577, in TypeInferer.resolve_call(self, fnty, pos_args, kw_args)
   1574     return sig
   1575 else:
   1576     # Normal non-recursive call
-> 1577     return self.context.resolve_function_type(fnty, pos_args, kw_args)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typing/context.py:196, in BaseContext.resolve_function_type(self, func, args, kws)
    194 # Prefer user definition first
    195 try:
--> 196     res = self._resolve_user_function_type(func, args, kws)
    197 except errors.TypingError as e:
    198     # Capture any typing error
    199     last_exception = e

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typing/context.py:248, in BaseContext._resolve_user_function_type(self, func, args, kws, literals)
    244         return self.resolve_function_type(func_type, args, kws)
    246 if isinstance(func, types.Callable):
    247     # XXX fold this into the __call__ attribute logic?
--> 248     return func.get_call_type(self, args, kws)

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/types/functions.py:541, in Dispatcher.get_call_type(self, context, args, kws)
    534 def get_call_type(self, context, args, kws):
    535     """
    536     Resolve a call to this dispatcher using the given argument types.
    537     A signature returned and it is ensured that a compiled specialization
    538     is available for it.
    539     """
    540     template, pysig, args, kws = \
--> 541         self.dispatcher.get_call_template(args, kws)
    542     sig = template(context).apply(args, kws)
    543     if sig:

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:314, in _DispatcherBase.get_call_template(self, args, kws)
    304 """
    305 Get a typing.ConcreteTemplate for this dispatcher and the given
    306 *args* and *kws* types.  This allows to resolve the return type.
    307 
    308 A (template, pysig, args, kws) tuple is returned.
    309 """
    310 # XXX how about a dispatcher template class automating the
    311 # following?
    312 
    313 # Fold keyword arguments and resolve default values
--> 314 pysig, args = self._compiler.fold_argument_types(args, kws)
    315 kws = {}
    316 # Ensure an overload is available

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/dispatcher.py:73, in _FunctionCompiler.fold_argument_types(self, args, kws)
     71     return types.StarArgTuple(values)
     72 # For now, we take argument values from the @jit function
---> 73 args = fold_arguments(self.pysig, args, kws,
     74                       normal_handler,
     75                       default_handler,
     76                       stararg_handler)
     77 return self.pysig, args

File ~/mambaforge/envs/py3.10/lib/python3.10/site-packages/numba/core/typing/templates.py:220, in fold_arguments(pysig, args, kws, normal_handler, default_handler, stararg_handler)
    217         bind_kws[n] = args[len(kwonly) + idx]
    219 # now bind
--> 220 ba = pysig.bind(*bind_args, **bind_kws)
    221 for i, param in enumerate(pysig.parameters.values()):
    222     name = param.name

File ~/mambaforge/envs/py3.10/lib/python3.10/inspect.py:3186, in Signature.bind(self, *args, **kwargs)
   3181 def bind(self, /, *args, **kwargs):
   3182     """Get a BoundArguments object, that maps the passed `args`
   3183     and `kwargs` to the function's signature.  Raises `TypeError`
   3184     if the passed arguments can not be bound.
   3185     """
-> 3186     return self._bind(args, kwargs)

File ~/mambaforge/envs/py3.10/lib/python3.10/inspect.py:3101, in Signature._bind(self, args, kwargs, partial)
   3099                 msg = 'missing a required argument: {arg!r}'
   3100                 msg = msg.format(arg=param.name)
-> 3101                 raise TypeError(msg) from None
   3102 else:
   3103     # We have a positional argument to process
   3104     try:

TypeError: missing a required argument: 'b'
```




Discussion:

Patch:
diff --git a/docs/upcoming_changes/9799.bug_fix.rst b/docs/upcoming_changes/9799.bug_fix.rst
new file mode 100644
index 000000000..fee9f9ed2
--- /dev/null
+++ b/docs/upcoming_changes/9799.bug_fix.rst
@@ -0,0 +1,7 @@
+Fix regression in type-inference for star-arg arguments.
+--------------------------------------------------------
+
+A regression, that occurred between versions 0.59.0 and 0.60.0, in the
+type-inference associated with star-arg arguments has been fixed. The cause of
+the regression was the code for star-args handling in type-inference not being
+updated following the switch to use new-style error handling by default.
diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py
index e8a7d824c..04b411bac 100644
--- a/numba/core/typeinfer.py
+++ b/numba/core/typeinfer.py
@@ -518,14 +518,14 @@ def fold_arg_vars(typevars, args, vararg, kws):
             const_val = args[-1].literal_value
             # Is the constant value a tuple?
             if not isinstance(const_val, tuple):
-                raise TypeError(errmsg % (args[-1],))
+                raise TypingError(errmsg % (args[-1],))
             # Append the elements in the const tuple to the positional args
             pos_args += const_val
         # Handle non-constant
         elif not isinstance(args[-1], types.BaseTuple):
             # Unsuitable for *args
             # (Python is more lenient and accepts all iterables)
-            raise TypeError(errmsg % (args[-1],))
+            raise TypingError(errmsg % (args[-1],))
         else:
             # Append the elements in the tuple to the positional args
             pos_args += args[-1].types
diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py
index 2b371cfe7..2bc465eea 100644
--- a/numba/core/typing/templates.py
+++ b/numba/core/typing/templates.py
@@ -217,7 +217,15 @@ def fold_arguments(pysig, args, kws, normal_handler, default_handler,
             bind_kws[n] = args[len(kwonly) + idx]
 
     # now bind
-    ba = pysig.bind(*bind_args, **bind_kws)
+    try:
+        ba = pysig.bind(*bind_args, **bind_kws)
+    except TypeError as e:
+        # The binding attempt can raise if the args don't match up, this needs
+        # to be converted to a TypingError so that e.g. partial type inference
+        # doesn't just halt.
+        msg = (f"Cannot bind 'args={bind_args} kws={bind_kws}' to "
+               f"signature '{pysig}' due to \"{type(e).__name__}: {e}\".")
+        raise TypingError(msg)
     for i, param in enumerate(pysig.parameters.values()):
         name = param.name
         default = param.default


Test patch:
diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py
index 59ffe018b..11689b245 100644
--- a/numba/tests/test_builtins.py
+++ b/numba/tests/test_builtins.py
@@ -13,7 +13,7 @@ from numba import jit, typeof, njit, typed
 from numba.core import errors, types, config
 from numba.tests.support import (TestCase, tag, ignore_internal_warnings,
                                  MemoryLeakMixin)
-from numba.core.extending import overload_method, box
+from numba.core.extending import overload_method, box, register_jitable
 
 
 forceobj_flags = {'forceobj': True}
@@ -1369,6 +1369,88 @@ class TestIsinstanceBuiltin(TestCase):
             got = foo(x)
             self.assertEqual(got, expected)
 
+    def test_branch_prune_and_bind_to_sig(self):
+        # see issue 9795
+        @register_jitable
+        def f(x, y):
+            return x + y
+
+        @njit
+        def call_f(x):
+            if isinstance(x, tuple):
+                return f(*x)
+            else:
+                return f(x)
+
+        # The issue is that without isinstance and branch pruning working
+        # correctly, an attempt will be made to bind the function `f` with
+        # argument `x`. If `x` is a Tuple type, this will fail on the `else`
+        # branch as `f` takes two arguments opposed to one.
+        x = (1, 2)
+        self.assertEqual(call_f(x), call_f.py_func(x))
+
+
+        # This should raise as partial type inference and branch pruning will
+        # remove the `f(*x)` branch and just leave `f(x)`, which then won't
+        # bind because `f` takes two arguments and only one is supplied.
+        with self.assertRaises(errors.TypingError) as raises:
+            call_f(1)
+
+        msg = str(raises.exception)
+        self.assertIn("Cannot bind", msg)
+        self.assertIn("TypeError: missing a required argument: 'y'", msg)
+
+    def test_branch_prune_non_tuples_as_star_arg(self):
+
+        # see issue 9795
+        @register_jitable
+        def f(x, y):
+            return x + y
+
+        @register_jitable
+        def g(x):
+            return x
+
+        @njit
+        def call_f(x):
+            if isinstance(x, tuple):
+                return f(*x)
+            else:
+                return g(x)
+
+        # The issue is that without isinstance and branch pruning working
+        # correctly, an attempt will be made to bind the function `f` with
+        # argument `x`. If `x` is a non-tuple type `*x` will not bind to the
+        # signature of `f`.
+        x = 1
+        self.assertEqual(call_f(x), call_f.py_func(x))
+
+    def test_branch_prune_literal_as_star_arg(self):
+
+        # see issue 9795
+        @register_jitable
+        def f(x, y):
+            return x + y
+
+        @register_jitable
+        def g(x):
+            return x
+
+        one = 1
+        @njit
+        def call_f():
+            x = one
+            if isinstance(x, tuple):
+                return f(*x)
+            else:
+                return g(x)
+
+        # The issue is that without isinstance and branch pruning working
+        # correctly, an attempt will be made to bind the function `f` with
+        # argument `x`. If `x` is a non-tuple const value type `*x` will not
+        # bind to the signature of `f`.
+        self.assertEqual(call_f(), call_f.py_func())
+
 
 class TestGetattrBuiltin(MemoryLeakMixin, TestCase):
     # Tests the getattr() builtin