diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py
index 4370afdad..de3eb261d 100644
--- a/numba/core/typing/templates.py
+++ b/numba/core/typing/templates.py
@@ -517,9 +517,17 @@ class _OverloadFunctionTemplate(AbstractTemplate):
             inline_worker = InlineWorker(tyctx, tgctx, fcomp.locals,
                                          compiler_inst, flags, None,)
 
-            ir = inline_worker.run_untyped_passes(disp_type.dispatcher.py_func)
+            # If the inlinee contains something to trigger literal arg dispatch
+            # then the pipeline call will unconditionally fail due to a raised
+            # ForceLiteralArg exception. Therefore `resolve` is run first, as
+            # type resolution must occur at some point, this will hit any
+            # `literally` calls and because it's going via the dispatcher will
+            # handle them correctly i.e. ForceLiteralArg propagates. This having
+            # the desired effect of ensuring the pipeline call is only made in
+            # situations that will succeed. For context see #5887.
             resolve = disp_type.dispatcher.get_call_template
             template, pysig, folded_args, kws = resolve(new_args, kws)
+            ir = inline_worker.run_untyped_passes(disp_type.dispatcher.py_func)
 
             typemap, return_type, calltypes = typed_passes.type_inference_stage(
                 self.context, ir, folded_args, None)

Regression with literally and overloads with inline='always'
- [x] I am using the latest released version of Numba (most recent is visible in
 the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

Hi, 

While trying to migrate to Numba 0.50 we encountered the following problem with literally that may now fail if called from overloads compiled with inline='always'. The error itself looks like this:
```
DEBUG: dtype= unicode_type
Traceback (most recent call last):
  File "test_inline_literally.py", line 36, in <module>
    res = test_impl(data, dtype)
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 401, in _compile_for_args
    error_rewrite(e, 'typing')
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 344, in error_rewrite
    reraise(type(e), e, None)
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\utils.py", line 79, in reraise
    raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x0000023CF5AA24F0>.
'NoneType' object is not callable
[1] During: resolving callee type: Function(<function foo at 0x0000023CF24E5280>)
[2] During: typing of call at test_inline_literally.py (32)

Enable logging at debug level for details.

File "test_inline_literally.py", line 32:
def test_impl(arr, dtype):
    return foo(arr, dtype)
    ^
```

And below is the reproducer:
```
import numba
import numpy as np
from numba.extending import overload
from numba import types
from numba import literally


def foo(val, dtype):
    pass

@overload(foo, inline='always')    # seen with inline='always' only
def foo_ovld(arr, dtype):

    print("DEBUG: dtype=", dtype)
    if not isinstance(dtype, types.StringLiteral):
        def foo_noop(arr, dtype):
            return literally(dtype)
        return foo_noop

    if dtype.literal_value == 'str':
        def foo_as_str_impl(arr, dtype):
            return [str(x) for x in arr]
        return foo_as_str_impl

    if dtype.literal_value in ('int64', 'float64'):
        def foo_as_num_impl(arr, dtype):
            return list(arr.astype(np.dtype(dtype)))
        return foo_as_num_impl

@numba.njit
def test_impl(arr, dtype):
    return foo(arr, dtype)

data = np.asarray([1, 2, 3, 2, 4], dtype=np.int32)
dtype = 'int64'
print(test_impl(data, dtype))
```

The issue was found on 0.50.0rc1 but still remains in 0.51.0.dev0+56.g92df8df57
It seems it is somehow related to #5673 as it's not observed before it, but please note that even though test from our code base always passes on 0.49.1 the above script which is just simplified version might occasionally fail with 'Repeated literal typing request' as below:
```
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_inline_literally_2.py", line 20, in <module>
    res = test_impl(data, dtype)
  File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 376, in _compile_for_args
    return self._compile_for_args(*args)
  File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 369, in _compile_for_args
    raise errors.CompilerError(m.format(info))
numba.core.errors.CompilerError: Repeated literal typing request.
Arg #1 is Literal[str](int64).
This is likely caused by an error in typing. Please see nested and suppressed exceptions.
```
Not sure if this latter is a known issue and wasn't fixed already (please confirm if it's so).
But the main issue is of course new one _'NoneType' object is not callable_ problem.

Best Regards,
Alexey.

diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py
index 35aded544..cf5f3f620 100644
--- a/numba/tests/test_ir_inlining.py
+++ b/numba/tests/test_ir_inlining.py
@@ -6,7 +6,7 @@ LLVM or low level inlining.
 from itertools import product
 import numpy as np
 
-from numba import njit, typeof
+from numba import njit, typeof, literally
 from numba.core import types, ir, ir_utils, cgutils
 from numba.core.extending import (
     overload,
@@ -816,6 +816,48 @@ class TestOverloadInlining(MemoryLeakMixin, InliningBase):
         for val in consts:
             self.assertNotEqual(val.value, 1234)
 
+    def test_overload_inline_always_with_literally_in_inlinee(self):
+        # See issue #5887
+
+        def foo_ovld(dtype):
+
+            if not isinstance(dtype, types.StringLiteral):
+                def foo_noop(dtype):
+                    return literally(dtype)
+                return foo_noop
+
+            if dtype.literal_value == 'str':
+                def foo_as_str_impl(dtype):
+                    return 10
+                return foo_as_str_impl
+
+            if dtype.literal_value in ('int64', 'float64'):
+                def foo_as_num_impl(dtype):
+                    return 20
+                return foo_as_num_impl
+
+        # define foo for literal str 'str'
+        def foo(dtype):
+            return 10
+
+        overload(foo, inline='always')(foo_ovld)
+
+        def test_impl(dtype):
+            return foo(dtype)
+
+        # check literal dispatch on 'str'
+        dtype = 'str'
+        self.check(test_impl, dtype, inline_expect={'foo': True})
+
+        # redefine foo to be correct for literal str 'int64'
+        def foo(dtype):
+            return 20
+        overload(foo, inline='always')(foo_ovld)
+
+        # check literal dispatch on 'int64'
+        dtype = 'int64'
+        self.check(test_impl, dtype, inline_expect={'foo': True})
+
 
 class TestOverloadMethsAttrsInlining(InliningBase):
     def setUp(self):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc g++
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi @ file:///croot/certifi_1671487769961/work/certifi
exceptiongroup==1.2.2
importlib-metadata==6.7.0
iniconfig==2.0.0
llvmlite==0.33.0
-e git+https://github.com/numba/numba.git@92df8df57dd31a3da51d3b0cf94a4ec2b591f71a#egg=numba
numpy==1.21.6
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
tomli==2.0.1
typing_extensions==4.7.1
zipp==3.15.0

name: numba
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - argparse==1.4.0
      - exceptiongroup==1.2.2
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - llvmlite==0.33.0
      - numpy==1.21.6
      - packaging==24.0
      - pluggy==1.2.0
      - pytest==7.4.4
      - tomli==2.0.1
      - typing-extensions==4.7.1
      - zipp==3.15.0
prefix: /opt/conda/envs/numba

numba/tests/test_ir_inlining.py::TestOverloadInlining::test_overload_inline_always_with_literally_in_inlinee
numba/tests/test_ir_inlining.py::TestFunctionInlining::test_basic_inline_always numba/tests/test_ir_inlining.py::TestFunctionInlining::test_basic_inline_combos numba/tests/test_ir_inlining.py::TestFunctionInlining::test_basic_inline_never numba/tests/test_ir_inlining.py::TestFunctionInlining::test_freevar_bindings numba/tests/test_ir_inlining.py::TestFunctionInlining::test_global_binding numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_closure_inside_inlinable_inside_closure numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_from_another_module numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_from_another_module_as_freevar numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_from_another_module_w_2_getattr numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_from_another_module_w_getattr numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_inside_closure_inside_loop numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_inside_loop numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_involved numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inline_w_freevar_from_another_module numba/tests/test_ir_inlining.py::TestFunctionInlining::test_inlining_models numba/tests/test_ir_inlining.py::TestRegisterJitableInlining::test_register_jitable_inlines numba/tests/test_ir_inlining.py::TestOverloadInlining::test_basic_inline_always numba/tests/test_ir_inlining.py::TestOverloadInlining::test_basic_inline_combos numba/tests/test_ir_inlining.py::TestOverloadInlining::test_basic_inline_never numba/tests/test_ir_inlining.py::TestOverloadInlining::test_freevar_bindings numba/tests/test_ir_inlining.py::TestOverloadInlining::test_global_overload_binding numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_always_kw_no_default numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_from_another_module numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_from_another_module_as_freevar numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_from_another_module_w_2_getattr numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_from_another_module_w_getattr numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_stararg_error numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inline_w_freevar_from_another_module numba/tests/test_ir_inlining.py::TestOverloadInlining::test_inlining_models numba/tests/test_ir_inlining.py::TestOverloadInlining::test_multiple_overloads_with_different_inline_characteristics numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_attribute_always numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_attribute_costmodel_must_inline numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_attribute_costmodel_no_inline numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_attribute_never numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_method_cost_driven_always numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_method_cost_driven_must_inline numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_method_cost_driven_never numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_method_cost_driven_no_inline numba/tests/test_ir_inlining.py::TestOverloadMethsAttrsInlining::test_overload_method_default_args_always numba/tests/test_ir_inlining.py::TestGeneralInlining::test_inlining_optional_constant numba/tests/test_ir_inlining.py::TestGeneralInlining::test_with_inlined_and_noninlined_variants numba/tests/test_ir_inlining.py::TestGeneralInlining::test_with_kwargs numba/tests/test_ir_inlining.py::TestGeneralInlining::test_with_kwargs2 numba/tests/test_ir_inlining.py::TestInlineOptions::test_basic numba/tests/test_ir_inlining.py::TestInlineMiscIssues::test_issue4691 numba/tests/test_ir_inlining.py::TestInlineMiscIssues::test_issue4693 numba/tests/test_ir_inlining.py::TestInlineMiscIssues::test_issue5476 numba/tests/test_ir_inlining.py::TestInlineMiscIssues::test_issue5792 numba/tests/test_ir_inlining.py::TestInlineMiscIssues::test_issue5824
numba/core/typing/templates.py
numba/core/typing/templates.py