Raise build-time error on incomplete patterns

I realized I never intend to leave patterns (e.g. pattern matching in a 'case'
clause) incomplete, i.e. some cases left missing. When I do that it means I
forgot, and I'd like GHC to highlight it by raising an error instead of just
warning. Vervis has lots of warnings so it's hard to detect among them.

I suppose in other kinds of software people sometimes leave incomplete patterns
intentionally / are okay with a runtime exception being thrown? In a web
application, I definitely want to handle all cases, and be in control of how
errors are handled and displayed in UI.
This commit is contained in:
fr33domlover 2022-06-26 13:54:37 +00:00
parent b557217957
commit a6e4587281
3 changed files with 4 additions and 1 deletions

View file

@ -922,6 +922,8 @@ createNoteC (Entity pidUser personUser) sharerUser summary audience note muTarge
if u == u'
then Nothing
else Just $ Right u'
checkParent _ _ =
error "A situation I missed in pattern matching, fix it?"
checkFederation remoteRecips = do
federation <- asksSite $ appFederation . appSettings
unless (federation || null remoteRecips) $

View file

@ -1302,6 +1302,7 @@ getOutboxActorEntity obid = do
(Just p, Nothing, Nothing) -> return $ ActorPerson p
(Nothing, Just j, Nothing) -> return $ ActorProject j
(Nothing, Nothing, Just r) -> return $ ActorRepo r
_ -> error "obid used by multiple actors"
actorEntityPath (ActorPerson (Entity _ p)) =
LocalActorSharer . sharerIdent <$> getJust (personIdent p)

View file

@ -399,7 +399,7 @@ library
if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT
ghc-options: -Wall -fwarn-tabs -O0
ghc-options: -Wall -fwarn-tabs -O0 -Werror=incomplete-patterns
else
ghc-options: -Wall -fwarn-tabs -O2