diff --git a/CHANGELOG.md b/CHANGELOG.md index 30bff8bbd415ffeb0051dd6530d8548b0e2ae408..db7eec1f5d070f4c91ff34b07b29df894731fbcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/Checks/WarnCheck.hs b/src/Checks/WarnCheck.hs index 0f1c1cd9ceedfee814b3cad03f5f96a13ff02c60..493e86fc638a423775faa8a74d98708153fafd92 100644 --- a/src/Checks/WarnCheck.hs +++ b/src/Checks/WarnCheck.hs @@ -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 -- ----------------------------------------------------------------------------- diff --git a/test/AliasClash.curry b/test/AliasClash.curry new file mode 100644 index 0000000000000000000000000000000000000000..0fc2b94e8e41be30b07aa5ce9d5672726e67d59f --- /dev/null +++ b/test/AliasClash.curry @@ -0,0 +1,5 @@ +module AliasClash (module AliasClash) where + +import List as AliasClash +import Maybe as A +import List as A