git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2329 from garyb/unused-operator-warnings
0c63639Gary Burgess
examples/warning/UnusedExplicitImportTypeOp.pursnew file+9
@@ -0,0 +1,9 @@
1+-- @shouldWarnWith UnusedExplicitImport
2+module Main where
3+
4+import Prelude (Unit, unit, pure)
5+import Control.Monad.Eff (Eff)
6+import Lib (type (~>), natId)
7+
8+main :: Eff () Unit
9+main = natId (pure unit)
examples/warning/UnusedExplicitImportTypeOp/Lib.pursnew file+8
@@ -0,0 +1,8 @@
1+module Lib where
2+
3+type Nat f g = ∀ x. f x → g x
4+
5+infixr 4 type Nat as ~>
6+
7+natId ∷ ∀ f. f ~> f
8+natId x = x
examples/warning/UnusedExplicitImportValOp.pursnew file+8
@@ -0,0 +1,8 @@
1+-- @shouldWarnWith UnusedExplicitImport
2+module Main where
3+
4+import Prelude (Unit, unit, pure, (+))
5+import Control.Monad.Eff (Eff)
6+
7+main :: Eff () Unit
8+main = pure unit
purescript.cabal+1
@@ -76,6 +76,7 @@ extra-source-files: examples/passing/*.purs
76 , examples/failing/OrphanInstance/*.purs
76 , examples/failing/OrphanInstance/*.purs
77 , examples/warning/*.purs
77 , examples/warning/*.purs
78 , examples/warning/*.js
78 , examples/warning/*.js
79+ , examples/warning/UnusedExplicitImportTypeOp/*.purs
79 , examples/docs/bower_components/purescript-prelude/src/*.purs
80 , examples/docs/bower_components/purescript-prelude/src/*.purs
80 , examples/docs/bower.json
81 , examples/docs/bower.json
81 , examples/docs/src/*.purs
82 , examples/docs/src/*.purs
src/Language/PureScript/AST/Declarations.hs+1−1
@@ -107,7 +107,7 @@ data SimpleErrorMessage
107 | MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
107 | MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
108 | ImportHidingModule ModuleName
108 | ImportHidingModule ModuleName
109 | UnusedImport ModuleName
109 | UnusedImport ModuleName
110− | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
110+ | UnusedExplicitImport ModuleName [Name] (Maybe ModuleName) [DeclarationRef]
111 | UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
111 | UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
112 | UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
112 | UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
113 | DuplicateSelectiveImport ModuleName
113 | DuplicateSelectiveImport ModuleName
src/Language/PureScript/Errors.hs+1−1
@@ -760,7 +760,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
760
760
761 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
761 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
762 paras [ line $ "The import of module " ++ markCode (runModuleName mn) ++ " contains the following unused references:"
762 paras [ line $ "The import of module " ++ markCode (runModuleName mn) ++ " contains the following unused references:"
763− , indent $ paras $ map line names
763+ , indent $ paras $ map (line . markCode . runName . Qualified Nothing) names
764 , line "It could be replaced with:"
764 , line "It could be replaced with:"
765 , indent $ line $ markCode $ showSuggestion msg ]
765 , indent $ line $ markCode $ showSuggestion msg ]
766
766
src/Language/PureScript/Linter/Imports.hs+12−12
@@ -243,7 +243,7 @@ lintImportDecl env mni qualifierName names declType allowImplicit =
243 didWarn' <- forM (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
243 didWarn' <- forM (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
244 let allCtors = dctorsForType mni tn
244 let allCtors = dctorsForType mni tn
245 -- If we've not already warned a type is unused, check its data constructors
245 -- If we've not already warned a type is unused, check its data constructors
246− unless' (runProperName tn `notElem` usedNames) $
246+ unless' (TyName tn `notElem` usedNames) $
247 case (c, dctors `intersect` allCtors) of
247 case (c, dctors `intersect` allCtors) of
248 (_, []) | c /= Just [] -> warn (UnusedDctorImport mni tn qualifierName allRefs)
248 (_, []) | c /= Just [] -> warn (UnusedDctorImport mni tn qualifierName allRefs)
249 (Just ctors, dctors') ->
249 (Just ctors, dctors') ->
@@ -335,18 +335,18 @@ findUsedRefs env mni qn names =
335matchName
335matchName
336 :: (ProperName 'ConstructorName -> Maybe (ProperName 'TypeName))
336 :: (ProperName 'ConstructorName -> Maybe (ProperName 'TypeName))
337 -> Name
337 -> Name
338− -> Maybe String
338+ -> Maybe Name
339−matchName _ (IdentName x) = Just $ showIdent x
339+matchName lookupDc (DctorName x) = TyName <$> lookupDc x
340−matchName _ (TyName x) = Just $ runProperName x
341−matchName _ (TyClassName x) = Just $ runProperName x
342−matchName lookupDc (DctorName x) = runProperName <$> lookupDc x
343−matchName _ _ = Nothing
340+matchName _ ModName{} = Nothing
344−
341+matchName _ name = Just name
342+
345−runDeclRef :: DeclarationRef -> Maybe String
343+runDeclRef :: DeclarationRef -> Maybe Name
346runDeclRef (PositionedDeclarationRef _ _ ref) = runDeclRef ref
344runDeclRef (PositionedDeclarationRef _ _ ref) = runDeclRef ref
347−runDeclRef (ValueRef ident) = Just $ showIdent ident
345+runDeclRef (ValueRef ident) = Just $ IdentName ident
346+runDeclRef (ValueOpRef op) = Just $ ValOpName op
348−runDeclRef (TypeRef pn _) = Just $ runProperName pn
347+runDeclRef (TypeRef pn _) = Just $ TyName pn
348+runDeclRef (TypeOpRef op) = Just $ TyOpName op
349−runDeclRef (TypeClassRef pn) = Just $ runProperName pn
349+runDeclRef (TypeClassRef pn) = Just $ TyClassName pn
350runDeclRef _ = Nothing
350runDeclRef _ = Nothing
351
351
352checkDuplicateImports
352checkDuplicateImports