diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 258e34bc660beab1a5e95536a1d4bbcdeee5e232..69f3d31abbfa5ab2858d95a036ba2936eddfbf8b 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -2098,8 +2098,9 @@ addModule files = do
     checkTargetFile :: GhciMonad m => String -> m Bool
     checkTargetFile f = do
       exists <- liftIO (doesFileExist f)
-      unless exists $ liftIO $ hPutStrLn stderr $ "File " ++ f ++ " not found"
-      failIfExprEvalMode
+      unless exists $ do
+        liftIO $ hPutStrLn stderr $ "File " ++ f ++ " not found"
+        failIfExprEvalMode
       return exists
 
 -- | @:unadd@ command
diff --git a/testsuite/tests/ghci/should_run/T24115.hs b/testsuite/tests/ghci/should_run/T24115.hs
new file mode 100644
index 0000000000000000000000000000000000000000..d328e59028c26de52a5888b09072b1d9fa81a808
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T24115.hs
@@ -0,0 +1,2 @@
+
+loaded = True
diff --git a/testsuite/tests/ghci/should_run/T24115.script b/testsuite/tests/ghci/should_run/T24115.script
new file mode 100644
index 0000000000000000000000000000000000000000..28aa6232e0868a4f79e95df811dabab6f4bbed13
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T24115.script
@@ -0,0 +1 @@
+loaded
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index 9a73da55f48a35b5aee5bb0df9174ed3d0600e06..4f56d1e97170043fb28f040635e91c9dcac59ea5 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -92,3 +92,6 @@ test('T22958b', just_ghci, compile_and_run, [''])
 test('T22958c', just_ghci, compile_and_run, [''])
 test('GhciMainIs', just_ghci, compile_and_run, ['-main-is otherMain'])
 test('LargeBCO', [extra_files(['LargeBCO_A.hs']), req_interp, extra_hc_opts("-O -fbyte-code-and-object-code -fprefer-byte-code")], compile_and_run, [''])
+
+test('T24115', just_ghci + [extra_run_opts("-e ':add T24115.hs'")], ghci_script, ['T24115.script'])
+