git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1140 from purescript/warn-on-class-operator

Warn about declaring operators in classes

commit58acfae19ff7c81b803f005e6da5d04a604ed9c8 authorGary Burgess <gary.burgess@gmail.com> dateSat 6 Jun 2015, 18:02 (11 years ago) parentc3342ee76e1087
2 files changed+17−1
src/Language/PureScript/Errors.hs+7 src/Language/PureScript/Linter.hs+10−1
src/Language/PureScript/Errors.hs+7
@@ -119,6 +119,7 @@ data SimpleErrorMessage
119119 | TransitiveExportError DeclarationRef [DeclarationRef]
120120 | ShadowedName Ident
121121 | WildcardInferredType Type
122+ | ClassOperator ProperName Ident
122123 deriving (Show)
123124
124125-- |
@@ -226,6 +227,7 @@ errorCode em = case unwrapErrorMessage em of
226227 (TransitiveExportError _ _) -> "TransitiveExportError"
227228 (ShadowedName _) -> "ShadowedName"
228229 (WildcardInferredType _) -> "WildcardInferredType"
230+ (ClassOperator _ _) -> "ClassOperator"
229231
230232-- |
231233-- A stack trace for an error
@@ -543,6 +545,11 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
543545 : map (line . prettyPrintExport) ys
544546 goSimple (ShadowedName nm) =
545547 line $ "Name '" ++ show nm ++ "' was shadowed."
548+ goSimple (ClassOperator className opName) =
549+ paras [ line $ "Class '" ++ show className ++ "' declares operator " ++ show opName ++ "."
550+ , indent $ line $ "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
551+ , indent $ line $ show opName ++ " = someMember"
552+ ]
546553 goSimple (WildcardInferredType ty) =
547554 line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
548555 go (NotYetDefined names err) =
src/Language/PureScript/Linter.hs+10−1
@@ -51,11 +51,20 @@ lint (Module _ mn ds _) = censor (onErrorMessages (ErrorInModule mn)) $ mapM_ li
5151
5252 lintDeclaration :: Declaration -> m ()
5353 lintDeclaration d =
54− let (f, _, _, _, _) = everythingWithContextOnValues moduleNames mempty mappend def stepE stepB def def
54+ let (f, _, _, _, _) = everythingWithContextOnValues moduleNames mempty mappend stepD stepE stepB def def
5555 in tell (f d)
5656 where
5757 def s _ = (s, mempty)
5858
59+ stepD :: S.Set Ident -> Declaration -> (S.Set Ident, MultipleErrors)
60+ stepD s (TypeClassDeclaration name _ _ decls) = (s, foldr go mempty decls)
61+ where
62+ go :: Declaration -> MultipleErrors -> MultipleErrors
63+ go (PositionedDeclaration _ _ d') errs = go d' errs
64+ go (TypeDeclaration op@(Op _) _) errs = errorMessage (ClassOperator name op) <> errs
65+ go _ errs = errs
66+ stepD s _ = (s, mempty)
67+
5968 stepE :: S.Set Ident -> Expr -> (S.Set Ident, MultipleErrors)
6069 stepE s (Abs (Left name) _) = bind s name
6170 stepE s (Let ds' _) =