mirror of
https://github.com/haskell-nix/hnix.git
synced 2024-09-20 03:08:45 +03:00
Fix a problem with static processing of imports
This commit is contained in:
parent
b3fdc43998
commit
e9006ff98b
@ -78,31 +78,30 @@ staticImport
|
||||
MonadState (HashMap FilePath NExprLoc) m)
|
||||
=> SrcSpan -> FilePath -> m NExprLoc
|
||||
staticImport pann path = do
|
||||
imports <- get
|
||||
case M.lookup path imports of
|
||||
Just expr -> pure expr
|
||||
Nothing -> go
|
||||
where
|
||||
go = do
|
||||
mfile <- asks fst
|
||||
path <- liftIO $ pathToDefaultNixFile path
|
||||
path' <- liftIO $ pathToDefaultNixFile =<< canonicalizePath
|
||||
(maybe path (\p -> takeDirectory p </> path) mfile)
|
||||
|
||||
liftIO $ putStrLn $ "Importing file " ++ path'
|
||||
imports <- get
|
||||
case M.lookup path' imports of
|
||||
Just expr -> pure expr
|
||||
Nothing -> go path'
|
||||
where
|
||||
go path = do
|
||||
liftIO $ putStrLn $ "Importing file " ++ path
|
||||
|
||||
eres <- liftIO $ parseNixFileLoc path'
|
||||
eres <- liftIO $ parseNixFileLoc path
|
||||
case eres of
|
||||
Failure err -> error $ "Parse failed: " ++ show err
|
||||
Success x -> do
|
||||
let pos = SourcePos "Reduce.hs" (mkPos 1) (mkPos 1)
|
||||
span = SrcSpan pos pos
|
||||
cur = NamedVar (StaticKey "__cur_file" :| [])
|
||||
(Fix (NLiteralPath_ pann path')) pos
|
||||
(Fix (NLiteralPath_ pann path)) pos
|
||||
x' = Fix (NLet_ span [cur] x)
|
||||
modify (M.insert path x')
|
||||
local (const (Just path',
|
||||
emptyScopes @m @NExprLoc)) $ do
|
||||
local (const (Just path, emptyScopes @m @NExprLoc)) $ do
|
||||
x'' <- cata reduce x'
|
||||
modify (M.insert path x'')
|
||||
return x''
|
||||
|
Loading…
Reference in New Issue
Block a user