From d8a66c09ab08728b63d2c097318ecdaac874fe70 Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Sat, 9 Mar 2019 17:40:23 -0500 Subject: [PATCH] Ellipsis shouldn't introduce anything into scope --- src/Nix/Eval.hs | 15 +++++++-------- tests/eval-compare/ellipsis.nix | 3 +++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 tests/eval-compare/ellipsis.nix diff --git a/src/Nix/Eval.hs b/src/Nix/Eval.hs index 50aa698..ebba908 100644 --- a/src/Nix/Eval.hs +++ b/src/Nix/Eval.hs @@ -341,26 +341,25 @@ buildArgument params arg = do Nothing -> id Just n -> M.insert n $ const $ thunk (withScopes scope arg) - loebM (inject $ alignWithKey (assemble scope isVariadic) + loebM (inject $ M.mapMaybe id $ alignWithKey (assemble scope isVariadic) args (M.fromList s)) where assemble :: Scopes m t -> Bool -> Text -> These t (Maybe (m v)) - -> AttrSet t - -> m t + -> Maybe (AttrSet t -> m t) assemble scope isVariadic k = \case - That Nothing -> + That Nothing -> Just $ const $ evalError @v $ ErrorCall $ "Missing value for parameter: " ++ show k - That (Just f) -> \args -> + That (Just f) -> Just $ \args -> thunk $ withScopes scope $ pushScope args f - This x | isVariadic -> const (pure x) - | otherwise -> + This _ | isVariadic -> Nothing + | otherwise -> Just $ const $ evalError @v $ ErrorCall $ "Unexpected parameter: " ++ show k - These x _ -> const (pure x) + These x _ -> Just (const (pure x)) addSourcePositions :: (MonadReader e m, Has e SrcSpan) => Transform NExprLocF (m a) diff --git a/tests/eval-compare/ellipsis.nix b/tests/eval-compare/ellipsis.nix new file mode 100644 index 0000000..412222c --- /dev/null +++ b/tests/eval-compare/ellipsis.nix @@ -0,0 +1,3 @@ +let x = 1; + f = { ... }: x; +in f { x = 2; }