mirror of
https://github.com/haskell-nix/hnix.git
synced 2024-11-10 04:46:55 +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)
|
MonadState (HashMap FilePath NExprLoc) m)
|
||||||
=> SrcSpan -> FilePath -> m NExprLoc
|
=> SrcSpan -> FilePath -> m NExprLoc
|
||||||
staticImport pann path = do
|
staticImport pann path = do
|
||||||
|
mfile <- asks fst
|
||||||
|
path <- liftIO $ pathToDefaultNixFile path
|
||||||
|
path' <- liftIO $ pathToDefaultNixFile =<< canonicalizePath
|
||||||
|
(maybe path (\p -> takeDirectory p </> path) mfile)
|
||||||
|
|
||||||
imports <- get
|
imports <- get
|
||||||
case M.lookup path imports of
|
case M.lookup path' imports of
|
||||||
Just expr -> pure expr
|
Just expr -> pure expr
|
||||||
Nothing -> go
|
Nothing -> go path'
|
||||||
where
|
where
|
||||||
go = do
|
go path = do
|
||||||
mfile <- asks fst
|
liftIO $ putStrLn $ "Importing file " ++ path
|
||||||
path <- liftIO $ pathToDefaultNixFile path
|
|
||||||
path' <- liftIO $ pathToDefaultNixFile =<< canonicalizePath
|
|
||||||
(maybe path (\p -> takeDirectory p </> path) mfile)
|
|
||||||
|
|
||||||
liftIO $ putStrLn $ "Importing file " ++ path'
|
eres <- liftIO $ parseNixFileLoc path
|
||||||
|
|
||||||
eres <- liftIO $ parseNixFileLoc path'
|
|
||||||
case eres of
|
case eres of
|
||||||
Failure err -> error $ "Parse failed: " ++ show err
|
Failure err -> error $ "Parse failed: " ++ show err
|
||||||
Success x -> do
|
Success x -> do
|
||||||
let pos = SourcePos "Reduce.hs" (mkPos 1) (mkPos 1)
|
let pos = SourcePos "Reduce.hs" (mkPos 1) (mkPos 1)
|
||||||
span = SrcSpan pos pos
|
span = SrcSpan pos pos
|
||||||
cur = NamedVar (StaticKey "__cur_file" :| [])
|
cur = NamedVar (StaticKey "__cur_file" :| [])
|
||||||
(Fix (NLiteralPath_ pann path')) pos
|
(Fix (NLiteralPath_ pann path)) pos
|
||||||
x' = Fix (NLet_ span [cur] x)
|
x' = Fix (NLet_ span [cur] x)
|
||||||
modify (M.insert path x')
|
modify (M.insert path x')
|
||||||
local (const (Just path',
|
local (const (Just path, emptyScopes @m @NExprLoc)) $ do
|
||||||
emptyScopes @m @NExprLoc)) $ do
|
|
||||||
x'' <- cata reduce x'
|
x'' <- cata reduce x'
|
||||||
modify (M.insert path x'')
|
modify (M.insert path x'')
|
||||||
return x''
|
return x''
|
||||||
|
Loading…
Reference in New Issue
Block a user