git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1140 from purescript/warn-on-class-operator
58acfaeGary Burgess
src/Language/PureScript/Errors.hs+7
@@ -119,6 +119,7 @@ data SimpleErrorMessage
119 | TransitiveExportError DeclarationRef [DeclarationRef]
119 | TransitiveExportError DeclarationRef [DeclarationRef]
120 | ShadowedName Ident
120 | ShadowedName Ident
121 | WildcardInferredType Type
121 | WildcardInferredType Type
122+ | ClassOperator ProperName Ident
122 deriving (Show)
123 deriving (Show)
123
124
124-- |
125-- |
@@ -226,6 +227,7 @@ errorCode em = case unwrapErrorMessage em of
226 (TransitiveExportError _ _) -> "TransitiveExportError"
227 (TransitiveExportError _ _) -> "TransitiveExportError"
227 (ShadowedName _) -> "ShadowedName"
228 (ShadowedName _) -> "ShadowedName"
228 (WildcardInferredType _) -> "WildcardInferredType"
229 (WildcardInferredType _) -> "WildcardInferredType"
230+ (ClassOperator _ _) -> "ClassOperator"
229
231
230-- |
232-- |
231-- A stack trace for an error
233-- A stack trace for an error
@@ -543,6 +545,11 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
543 : map (line . prettyPrintExport) ys
545 : map (line . prettyPrintExport) ys
544 goSimple (ShadowedName nm) =
546 goSimple (ShadowedName nm) =
545 line $ "Name '" ++ show nm ++ "' was shadowed."
547 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+ ]
546 goSimple (WildcardInferredType ty) =
553 goSimple (WildcardInferredType ty) =
547 line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
554 line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
548 go (NotYetDefined names err) =
555 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
51
51
52 lintDeclaration :: Declaration -> m ()
52 lintDeclaration :: Declaration -> m ()
53 lintDeclaration d =
53 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
55 in tell (f d)
55 in tell (f d)
56 where
56 where
57 def s _ = (s, mempty)
57 def s _ = (s, mempty)
58
58
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+
59 stepE :: S.Set Ident -> Expr -> (S.Set Ident, MultipleErrors)
68 stepE :: S.Set Ident -> Expr -> (S.Set Ident, MultipleErrors)
60 stepE s (Abs (Left name) _) = bind s name
69 stepE s (Abs (Left name) _) = bind s name
61 stepE s (Let ds' _) =
70 stepE s (Let ds' _) =