git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1395 from nicodelpiano/master

Pass the length of arguments in as a function argument.

commitdfba11f1dd0a5b476ebd7f989f405b0bd7ff15fd authorPhil Freeman <paf31@cantab.net> dateMon 17 Aug 2015, 11:08 (11 years ago) parentaf3a5a985a291f
2 files changed+8−8
core-tests/tests/generic-deriving/Main.purs+5 src/Language/PureScript/Linter/Exhaustive.hs+3−8
core-tests/tests/generic-deriving/Main.purs+5
@@ -4,11 +4,16 @@ import Prelude
44
55import Data.Generic
66
7+data Void
8+
9+derive instance genericVoid :: Generic Void
10+
711data A a
812 = A Number String
913 | B Int
1014 | C (Array (A a))
1115 | D { a :: a }
16+ | E Void
1217
1318derive instance genericA :: (Generic a) => Generic (A a)
1419
src/Language/PureScript/Linter/Exhaustive.hs+3−8
@@ -228,8 +228,8 @@ missingAlternative env mn ca uncovered
228228-- it partitions that set with the new uncovered cases, until it consumes the whole set of clauses.
229229-- Then, returns the uncovered set of case alternatives.
230230--
231−checkExhaustive :: forall m. (MonadWriter MultipleErrors m) => Environment -> ModuleName -> [CaseAlternative] -> m ()
232−checkExhaustive env mn cas = makeResult . first nub $ foldl' step ([initial], (pure True, [])) cas
231+checkExhaustive :: forall m. (MonadWriter MultipleErrors m) => Environment -> ModuleName -> Int -> [CaseAlternative] -> m ()
232+checkExhaustive env mn numArgs cas = makeResult . first nub $ foldl' step ([initialize numArgs], (pure True, [])) cas
233233 where
234234 step :: ([[Binder]], (Maybe Bool, [[Binder]])) -> CaseAlternative -> ([[Binder]], (Maybe Bool, [[Binder]]))
235235 step (uncovered, (nec, redundant)) ca =
@@ -240,11 +240,6 @@ checkExhaustive env mn cas = makeResult . first nub $ foldl' step ([initial], (p
240240 where
241241 sequenceA = foldr (liftA2 (:)) (pure [])
242242
243− initial :: [Binder]
244− initial = initialize numArgs
245− where
246− numArgs = length . caseAlternativeBinders . head $ cas
247−
248243 makeResult :: ([[Binder]], (Maybe Bool, [[Binder]])) -> m ()
249244 makeResult (bss, (_, bss')) =
250245 do unless (null bss) tellExhaustive
@@ -274,7 +269,7 @@ checkExhaustiveDecls env mn ds =
274269 in mapM_ f' ds
275270 where
276271 checkExpr :: Expr -> m Expr
277− checkExpr c@(Case _ cas) = checkExhaustive env mn cas >> return c
272+ checkExpr c@(Case expr cas) = checkExhaustive env mn (length expr) cas >> return c
278273 checkExpr other = return other
279274
280275-- |