mirror of
https://github.com/anoma/juvix.git
synced 2024-09-19 04:27:20 +03:00
[tests] add test and error for missing function clause
This commit is contained in:
parent
b29050afb4
commit
028c6ac5c0
@ -53,6 +53,14 @@ infixErrorAux kind pp =
|
||||
"Error while resolving infixities in the" <+> kind <> ":" <> line
|
||||
<> indent' (highlight pp)
|
||||
|
||||
instance PrettyError LacksFunctionClause where
|
||||
ppError LacksFunctionClause {..} =
|
||||
pretty loc <> line <>
|
||||
"There is a type signature no function clause:" <> line
|
||||
<> indent' (highlight (ppCode _lacksFunctionClause))
|
||||
where
|
||||
loc = getLoc $ _sigName _lacksFunctionClause
|
||||
|
||||
instance PrettyError LacksTypeSig where
|
||||
ppError LacksTypeSig {..} =
|
||||
pretty loc <> line <>
|
||||
|
@ -33,6 +33,12 @@ newtype LacksTypeSig = LacksTypeSig {
|
||||
}
|
||||
deriving stock (Show)
|
||||
|
||||
-- | type signature without a function clause
|
||||
newtype LacksFunctionClause = LacksFunctionClause {
|
||||
_lacksFunctionClause :: TypeSignature 'Scoped
|
||||
}
|
||||
deriving stock (Show)
|
||||
|
||||
newtype ImportCycle = ImportCycle {
|
||||
-- | If we have [a, b, c] it means that a import b imports c imports a.
|
||||
_importCycleImports :: NonEmpty (Import 'Parsed)
|
||||
|
@ -495,6 +495,7 @@ checkModuleBody :: forall r.
|
||||
checkModuleBody body = do
|
||||
body' <- mapM checkStatement body
|
||||
checkOrphanFixities
|
||||
checkClausesExist body'
|
||||
exported <- get >>= exportScope
|
||||
return (exported, body')
|
||||
|
||||
@ -532,7 +533,14 @@ checkLocalModule Module {..} = do
|
||||
inheritEntry :: SymbolEntry -> SymbolEntry
|
||||
inheritEntry = over S.nameWhyInScope S.BecauseInherited
|
||||
|
||||
checkOrphanFixities :: forall r .Members '[Error ScopeError, State Scope] r => Sem r ()
|
||||
checkClausesExist :: forall r. Members '[Error ScopeError, State Scope] r => [Statement 'Scoped] -> Sem r ()
|
||||
checkClausesExist ss = whenJust msig (throw . ErrLacksFunctionClause . LacksFunctionClause)
|
||||
where
|
||||
msig = listToMaybe [ ts | StatementTypeSignature ts <- ss,
|
||||
null [ c | StatementFunctionClause c <- ss ,
|
||||
c ^. clauseOwnerFunction == ts ^. sigName]]
|
||||
|
||||
checkOrphanFixities :: forall r. Members '[Error ScopeError, State Scope] r => Sem r ()
|
||||
checkOrphanFixities = do
|
||||
path <- gets _scopePath
|
||||
declared <- gets _scopeFixities
|
||||
@ -542,7 +550,6 @@ checkOrphanFixities = do
|
||||
[] -> return ()
|
||||
(x : _) -> throw (ErrUnusedOperatorDef (UnusedOperatorDef x))
|
||||
|
||||
|
||||
symbolInfoSingle :: SymbolEntry -> SymbolInfo
|
||||
symbolInfoSingle p = SymbolInfo $ HashMap.singleton (S._nameDefinedIn p) p
|
||||
|
||||
|
@ -118,4 +118,11 @@ tests = [
|
||||
case er of
|
||||
ErrAmbiguousSym {} -> Nothing
|
||||
_ -> wrongError
|
||||
, NegTest "Lacks function clause"
|
||||
"."
|
||||
"LacksFunctionClause.mjuvix" $ \er ->
|
||||
case er of
|
||||
ErrLacksFunctionClause {} -> Nothing
|
||||
_ -> wrongError
|
||||
|
||||
]
|
||||
|
4
tests/negative/LacksFunctionClause.mjuvix
Normal file
4
tests/negative/LacksFunctionClause.mjuvix
Normal file
@ -0,0 +1,4 @@
|
||||
module LacksFunctionClause;
|
||||
|
||||
id : Type → Type → Type;
|
||||
end;
|
Loading…
Reference in New Issue
Block a user