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

Implemented warnings for overlapping module aliases - fixes #14

parent 5c6b4664
......@@ -4,6 +4,8 @@ Change log for curry-frontend
Under development
=================
* Implemented warnings for overlapping module aliases - fixes #14
* The check for overlapping rules has been completely refactored and
improved to now also handle rigid case expressions.
......
......@@ -38,6 +38,7 @@ import qualified Base.ScopeEnv as SE
, lookupWithLevel, toLevelList, currentLevel)
import Base.Types
import Base.Utils (findMultiples)
import Env.ModuleAlias
import Env.TypeConstructor (TCEnv, TypeInfo (..), lookupTC, qualLookupTC)
import Env.Value (ValueEnv, ValueInfo (..), lookupValue, qualLookupValue)
......@@ -59,6 +60,7 @@ warnCheck opts aEnv valEnv tcEnv (Module _ mid es is ds)
checkImports is
checkDeclGroup ds
checkMissingTypeSignatures ds
checkModuleAlias is
type ScopeEnv = SE.ScopeEnv QualIdent IdInfo
......@@ -428,6 +430,35 @@ warnMissingTypeSignature mid i tys = posMessage i $ hsep (map text
["Top-level binding with no type signature:", showIdent i, "::"])
<+> ppTypeScheme mid tys
-- -----------------------------------------------------------------------------
-- Check for overlapping module alias names
-- -----------------------------------------------------------------------------
-- check if module aliases in import declarations overlap with the module name
-- or another module alias
checkModuleAlias :: [ImportDecl] -> WCM ()
checkModuleAlias is = do
mid <- getModuleIdent
let alias = catMaybes [a | ImportDecl _ _ _ a _ <- is]
modClash = [a | a <- alias, a == mid]
aliasClash = findMultiples alias
unless (null modClash) $ mapM_ (report . warnModuleNameClash) modClash
unless (null aliasClash) $ mapM_ (report . warnAliasNameClash) aliasClash
warnModuleNameClash :: ModuleIdent -> Message
warnModuleNameClash mid = posMessage mid $ hsep $ map text
["The module alias", escModuleName mid
, "overlaps with the current module name"]
warnAliasNameClash :: [ModuleIdent] -> Message
warnAliasNameClash [] = internalError
"WarnCheck.warnAliasNameClash: empty list"
warnAliasNameClash mids = posMessage (head mids) $ text
"Overlapping module aliases" $+$ nest 2 (vcat (map myppAlias mids))
where myppAlias mid@(ModuleIdent pos _) =
ppLine pos <> text ":" <+> text (escModuleName mid)
-- -----------------------------------------------------------------------------
-- Check for overlapping and non-exhaustive case alternatives
-- -----------------------------------------------------------------------------
......
module AliasClash (module AliasClash) where
import List as AliasClash
import Maybe as A
import List as A
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