Commit a37fcbd5 authored by Jan Rasmus Tikovsky 's avatar Jan Rasmus Tikovsky

Added warnings for top-level functions without type signatures - fixes #769

parent 954a0bfc
...@@ -4,7 +4,11 @@ Change log for curry-frontend ...@@ -4,7 +4,11 @@ Change log for curry-frontend
Under development Under development
================= =================
* Type synonyms in typed expressions are now desugared - fixes #921 * Added warnings for top-level functions without type signatures - fixes #769
* Moved pretty-printing of types from Checks.TypeCheck to Base.CurryTypes
* Type synonyms in typed expressions are now desugared - fixes #921
* Declaration of operator precedence is now optional in infix operator * Declaration of operator precedence is now optional in infix operator
declarations declarations
......
...@@ -28,6 +28,7 @@ import Curry.Base.Pretty ...@@ -28,6 +28,7 @@ import Curry.Base.Pretty
import Curry.Syntax import Curry.Syntax
import Curry.Syntax.Pretty (ppPattern, ppExpr, ppIdent) import Curry.Syntax.Pretty (ppPattern, ppExpr, ppIdent)
import Base.CurryTypes (ppTypeScheme)
import Base.Messages (Message, posMessage, internalError) import Base.Messages (Message, posMessage, internalError)
import qualified Base.ScopeEnv as SE import qualified Base.ScopeEnv as SE
( ScopeEnv, new, beginScope, endScopeUp, insert, lookup, level, modify ( ScopeEnv, new, beginScope, endScopeUp, insert, lookup, level, modify
...@@ -36,7 +37,7 @@ import qualified Base.ScopeEnv as SE ...@@ -36,7 +37,7 @@ import qualified Base.ScopeEnv as SE
import Base.Types import Base.Types
import Env.ModuleAlias import Env.ModuleAlias
import Env.TypeConstructor (TCEnv, TypeInfo (..), lookupTC, qualLookupTC) import Env.TypeConstructor (TCEnv, TypeInfo (..), lookupTC, qualLookupTC)
import Env.Value (ValueEnv, ValueInfo (..), qualLookupValue) import Env.Value (ValueEnv, ValueInfo (..), lookupValue, qualLookupValue)
import CompilerOpts import CompilerOpts
...@@ -54,6 +55,7 @@ warnCheck opts aEnv valEnv tcEnv (Module _ mid es is ds) ...@@ -54,6 +55,7 @@ warnCheck opts aEnv valEnv tcEnv (Module _ mid es is ds)
checkExports es checkExports es
checkImports is checkImports is
checkDeclGroup ds checkDeclGroup ds
checkMissingTypeSignatures ds
type ScopeEnv = SE.ScopeEnv QualIdent IdInfo type ScopeEnv = SE.ScopeEnv QualIdent IdInfo
...@@ -415,6 +417,32 @@ checkOverlappingAlts (alt : alts) = warnFor WarnOverlapping $ do ...@@ -415,6 +417,32 @@ checkOverlappingAlts (alt : alts) = warnFor WarnOverlapping $ do
eqPattern _ _ eqPattern _ _
= False = False
-- -----------------------------------------------------------------------------
-- Check for missing type signatures
-- -----------------------------------------------------------------------------
-- check if a type signature was specified for every top-level function
-- declaration
-- for external function declarations this check is already performed
-- during syntax checking
checkMissingTypeSignatures :: [Decl] -> WCM ()
checkMissingTypeSignatures decls = do
let tys = [t | TypeSig _ ts _ <- decls, t <- ts]
missingTys = [f | FunctionDecl _ f _ <- decls, f `notElem` tys]
unless (null missingTys) $ do
mid <- getModuleIdent
tyScs <- mapM getTyScheme missingTys
mapM_ report $ zipWith (warnMissingTypeSignature mid) missingTys tyScs
getTyScheme :: Ident -> WCM TypeScheme
getTyScheme q = do
tyEnv <- gets valueEnv
return $ case lookupValue q tyEnv of
[Value _ _ tys] -> tys
_ -> internalError $
"Checks.WarnCheck.getTyScheme: " ++ show q
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Check for non-exhaustive patterns -- Check for non-exhaustive patterns
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
...@@ -858,6 +886,11 @@ typeId = qualify . flip renameIdent 1 ...@@ -858,6 +886,11 @@ typeId = qualify . flip renameIdent 1
-- Warnings messages -- Warnings messages
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
warnMissingTypeSignature :: ModuleIdent -> Ident -> TypeScheme -> Message
warnMissingTypeSignature mid i tys = posMessage i $ hsep (map text
["Top-level binding with no type signature:", showIdent i, "::"])
<+> ppTypeScheme mid tys
warnMultiplyImportedModule :: ModuleIdent -> Message warnMultiplyImportedModule :: ModuleIdent -> Message
warnMultiplyImportedModule mid = posMessage mid $ hsep $ map text warnMultiplyImportedModule mid = posMessage mid $ hsep $ map text
["Module", moduleName mid, "is imported more than once"] ["Module", moduleName mid, "is imported more than once"]
......
--hw :: String
hw = "Hello World"
f x = tail x
where
answer = 42
inc i = i + 1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment