 +          (\splicesDir -> do
 +              moduleSplicesPath <- getModuleSplicesPath splicesDir <$> getModule
 +              hs_splice_data <- readTcRef (tcg_hs_splice_data tcg_env)
-+              liftIO $ createDirectoryIfMissing True splicesDir
++              liftIO $ createDirectoryIfMissing True (takeDirectory moduleSplicesPath)
 +              writeHsSpliceData moduleSplicesPath hs_splice_data
 +          )
 +          (pure ())

 hsLitType (HsCharPrim _ _)   = charPrimTy
 hsLitType (HsString _ _)     = stringTy
diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs
index 40b5efec84..2f9cb2c3d2 100644
--- a/compiler/typecheck/TcRnDriver.hs
+++ b/compiler/typecheck/TcRnDriver.hs
@@ -44,7 +44,7 @@ module TcRnDriver (

 import ListSetOps
 import Outputable
 import ConLike
@@ -136,6 +137,8 @@ import HsDumpAst
 import qualified Data.Set as S
 
 import Control.Monad
+import System.Directory
+import System.FilePath (takeDirectory)
 
 #include "HsVersions.h"
 
@@ -417,6 +420,17 @@ tcRnSrcDecls explicit_mod_hdr decls
         -- Finalizers must run after constraints are simplified, or some types
         -- might not be complete when using reify (see #12777).
       ; (tcg_env, tcl_env) <- setGblEnv tcg_env run_th_modfinalizers
