git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve context info for lint warnings
ab73d58Gary Burgess
src/Language/PureScript/Errors.hs+8
@@ -170,6 +170,7 @@ data ErrorMessage
170 | ErrorInDataBindingGroup ErrorMessage
170 | ErrorInDataBindingGroup ErrorMessage
171 | ErrorInTypeSynonym ProperName ErrorMessage
171 | ErrorInTypeSynonym ProperName ErrorMessage
172 | ErrorInValueDeclaration Ident ErrorMessage
172 | ErrorInValueDeclaration Ident ErrorMessage
173+ | ErrorInTypeDeclaration Ident ErrorMessage
173 | ErrorInForeignImport Ident ErrorMessage
174 | ErrorInForeignImport Ident ErrorMessage
174 | PositionedError SourceSpan ErrorMessage
175 | PositionedError SourceSpan ErrorMessage
175 | SimpleErrorWrapper SimpleErrorMessage
176 | SimpleErrorWrapper SimpleErrorMessage
@@ -340,6 +341,7 @@ unwrapErrorMessage em = case em of
340 (ErrorInTypeConstructor _ err) -> unwrapErrorMessage err
341 (ErrorInTypeConstructor _ err) -> unwrapErrorMessage err
341 (ErrorInTypeSynonym _ err) -> unwrapErrorMessage err
342 (ErrorInTypeSynonym _ err) -> unwrapErrorMessage err
342 (ErrorInValueDeclaration _ err) -> unwrapErrorMessage err
343 (ErrorInValueDeclaration _ err) -> unwrapErrorMessage err
344+ (ErrorInTypeDeclaration _ err) -> unwrapErrorMessage err
343 (ErrorInferringType _ err) -> unwrapErrorMessage err
345 (ErrorInferringType _ err) -> unwrapErrorMessage err
344 (ErrorUnifyingTypes _ _ err) -> unwrapErrorMessage err
346 (ErrorUnifyingTypes _ _ err) -> unwrapErrorMessage err
345 (NotYetDefined _ err) -> unwrapErrorMessage err
347 (NotYetDefined _ err) -> unwrapErrorMessage err
@@ -386,6 +388,7 @@ onTypesInErrorMessageM f = g
386 g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> (g e)
388 g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> (g e)
387 g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> (g e)
389 g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> (g e)
388 g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> (g e)
390 g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> (g e)
391+ g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> (g e)
389 g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> (g e)
392 g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> (g e)
390 g (PositionedError x e) = PositionedError x <$> (g e)
393 g (PositionedError x e) = PositionedError x <$> (g e)
391 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
394 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
@@ -740,6 +743,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
740 paras [ lineWithLevel $ "in value declaration " ++ showIdent n ++ ":"
743 paras [ lineWithLevel $ "in value declaration " ++ showIdent n ++ ":"
741 , go err
744 , go err
742 ]
745 ]
746+ go (ErrorInTypeDeclaration n err) =
747+ paras [ lineWithLevel $ "in type declaration for " ++ showIdent n ++ ":"
748+ , go err
749+ ]
743 go (ErrorInForeignImport nm err) =
750 go (ErrorInForeignImport nm err) =
744 paras [ lineWithLevel $ "in foreign import " ++ showIdent nm ++ ":"
751 paras [ lineWithLevel $ "in foreign import " ++ showIdent nm ++ ":"
745 , go err
752 , go err
@@ -805,6 +812,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
805 unwrap pos (ErrorInDataBindingGroup err) = ErrorInDataBindingGroup (unwrap pos err)
812 unwrap pos (ErrorInDataBindingGroup err) = ErrorInDataBindingGroup (unwrap pos err)
806 unwrap pos (ErrorInTypeSynonym nm err) = ErrorInTypeSynonym nm (unwrap pos err)
813 unwrap pos (ErrorInTypeSynonym nm err) = ErrorInTypeSynonym nm (unwrap pos err)
807 unwrap pos (ErrorInValueDeclaration nm err) = ErrorInValueDeclaration nm (unwrap pos err)
814 unwrap pos (ErrorInValueDeclaration nm err) = ErrorInValueDeclaration nm (unwrap pos err)
815+ unwrap pos (ErrorInTypeDeclaration nm err) = ErrorInTypeDeclaration nm (unwrap pos err)
808 unwrap pos (ErrorInForeignImport nm err) = ErrorInForeignImport nm (unwrap pos err)
816 unwrap pos (ErrorInForeignImport nm err) = ErrorInForeignImport nm (unwrap pos err)
809 unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
817 unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
810 unwrap _ (PositionedError pos err) = unwrap (Just pos) err
818 unwrap _ (PositionedError pos err) = unwrap (Just pos) err
src/Language/PureScript/Linter.hs+11−9
@@ -60,7 +60,9 @@ lint (Module _ _ mn ds _) = censor (onErrorMessages (ErrorInModule mn)) $ mapM_
60
60
61 f' :: Declaration -> MultipleErrors
61 f' :: Declaration -> MultipleErrors
62 f' (PositionedDeclaration pos _ dec) = onErrorMessages (PositionedError pos) (f' dec)
62 f' (PositionedDeclaration pos _ dec) = onErrorMessages (PositionedError pos) (f' dec)
63− f' dec = f dec <> checkTypeVars dec
63+ f' dec@(ValueDeclaration name _ _ _) = onErrorMessages (ErrorInValueDeclaration name) (f dec <> checkTypeVarsInDecl dec)
64+ f' (TypeDeclaration name ty) = onErrorMessages (ErrorInTypeDeclaration name) (checkTypeVars ty)
65+ f' dec = f dec <> checkTypeVarsInDecl dec
64
66
65 in tell (f' d)
67 in tell (f' d)
66 where
68 where
@@ -90,11 +92,11 @@ lint (Module _ _ mn ds _) = censor (onErrorMessages (ErrorInModule mn)) $ mapM_
90 bindName :: S.Set Ident -> Ident -> (S.Set Ident, MultipleErrors)
92 bindName :: S.Set Ident -> Ident -> (S.Set Ident, MultipleErrors)
91 bindName = bind ShadowedName
93 bindName = bind ShadowedName
92
94
93− checkTypeVars :: Declaration -> MultipleErrors
95+ checkTypeVarsInDecl :: Declaration -> MultipleErrors
94− checkTypeVars d =
96+ checkTypeVarsInDecl d = let (f, _, _, _, _) = accumTypes checkTypeVars in f d
97+
98+ checkTypeVars :: Type -> MultipleErrors
95− let (checkShadow, _, _, _, _) = accumTypes (everythingWithContextOnTypes S.empty mempty mappend step)
99+ checkTypeVars ty = everythingWithContextOnTypes S.empty mempty mappend step ty <> findUnused ty
96− (checkUnused, _, _, _, _) = accumTypes findUnused
97− in checkShadow d <> checkUnused d
98 where
100 where
99 step :: S.Set String -> Type -> (S.Set String, MultipleErrors)
101 step :: S.Set String -> Type -> (S.Set String, MultipleErrors)
100 step s (ForAll tv _ _) = bindVar s tv
102 step s (ForAll tv _ _) = bindVar s tv
@@ -102,9 +104,9 @@ lint (Module _ _ mn ds _) = censor (onErrorMessages (ErrorInModule mn)) $ mapM_
102 bindVar :: S.Set String -> String -> (S.Set String, MultipleErrors)
104 bindVar :: S.Set String -> String -> (S.Set String, MultipleErrors)
103 bindVar = bind ShadowedTypeVar
105 bindVar = bind ShadowedTypeVar
104 findUnused :: Type -> MultipleErrors
106 findUnused :: Type -> MultipleErrors
105− findUnused ty =
107+ findUnused ty' =
106− let used = usedTypeVariables ty
108+ let used = usedTypeVariables ty'
107− declared = everythingOnTypes (++) go ty
109+ declared = everythingOnTypes (++) go ty'
108 unused = nub declared \\ nub used
110 unused = nub declared \\ nub used
109 in foldl (<>) mempty $ map (errorMessage . UnusedTypeVar) unused
111 in foldl (<>) mempty $ map (errorMessage . UnusedTypeVar) unused
110 where
112 where