Skip to content

Commit 768a14b

Browse files
committed
Eval: m improve readability
1 parent 2950fee commit 768a14b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/Nix/Eval.hs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{-# LANGUAGE TupleSections #-}
1010
{-# LANGUAGE TypeApplications #-}
1111

12-
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12+
1313

1414
module Nix.Eval where
1515

@@ -262,21 +262,23 @@ evalBinds recursive binds = do
262262
(M.toList o')
263263

264264
go _ (NamedVar pathExpr finalValue pos) = do
265-
let go :: NAttrPath (m v) -> m ([Text], SourcePos, m v)
266-
go = \case
267-
h :| t -> evalSetterKeyName h >>= \case
268-
Nothing ->
269-
pure
270-
( mempty
271-
, nullPos
272-
, toValue @(AttrSet v, AttrSet SourcePos) (mempty, mempty)
273-
)
274-
Just k -> case t of
275-
[] -> pure ([k], pos, finalValue)
276-
x : xs -> do
277-
(restOfPath, _, v) <- go (x :| xs)
278-
pure (k : restOfPath, pos, v)
279-
go pathExpr <&> \case
265+
let
266+
gogo :: NAttrPath (m v) -> m ([Text], SourcePos, m v)
267+
gogo = \case
268+
h :| t -> evalSetterKeyName h >>= \case
269+
Nothing ->
270+
pure
271+
( mempty
272+
, nullPos
273+
, toValue @(AttrSet v, AttrSet SourcePos) (mempty, mempty)
274+
)
275+
Just k -> case t of
276+
[] -> pure ([k], pos, finalValue)
277+
x : xs -> do
278+
(restOfPath, _, v) <- gogo (x :| xs)
279+
pure (k : restOfPath, pos, v)
280+
281+
gogo pathExpr <&> \case
280282
-- When there are no path segments, e.g. `${null} = 5;`, we don't
281283
-- bind anything
282284
([], _, _) -> mempty
@@ -292,8 +294,8 @@ evalBinds recursive binds = do
292294
mv <- case ms of
293295
Nothing -> withScopes scope $ lookupVar key
294296
Just s ->
295-
s >>= fromValue @(AttrSet v, AttrSet SourcePos) >>= \(s, _) ->
296-
clearScopes @v $ pushScope s $ lookupVar key
297+
s >>= fromValue @(AttrSet v, AttrSet SourcePos) >>= \(attrset, _) ->
298+
clearScopes @v $ pushScope attrset $ lookupVar key
297299
case mv of
298300
Nothing -> attrMissing (key :| []) Nothing
299301
Just v -> demand v pure

0 commit comments

Comments
 (0)