git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix usage detection for operators
commit3f901d0a24be0039bad798bac6c4acf647e299c0 authorGary Burgess <gary.burgess@gmail.com> dateSat 24 Sep 2016, 14:50 (10 years ago) parenta84f7f3
7 files changed+40−14
examples/warning/UnusedExplicitImportTypeOp.purs+9 examples/warning/UnusedExplicitImportTypeOp/Lib.purs+8 examples/warning/UnusedExplicitImportValOp.purs+8 purescript.cabal+1 src/Language/PureScript/AST/Declarations.hs+1−1 src/Language/PureScript/Errors.hs+1−1 src/Language/PureScript/Linter/Imports.hs+12−12
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
7676 , examples/failing/OrphanInstance/*.purs
7777 , examples/warning/*.purs
7878 , examples/warning/*.js
79+ , examples/warning/UnusedExplicitImportTypeOp/*.purs
7980 , examples/docs/bower_components/purescript-prelude/src/*.purs
8081 , examples/docs/bower.json
8182 , examples/docs/src/*.purs
src/Language/PureScript/AST/Declarations.hs+1−1
@@ -107,7 +107,7 @@ data SimpleErrorMessage
107107 | MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
108108 | ImportHidingModule ModuleName
109109 | UnusedImport ModuleName
110− | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
110+ | UnusedExplicitImport ModuleName [Name] (Maybe ModuleName) [DeclarationRef]
111111 | UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
112112 | UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
113113 | DuplicateSelectiveImport ModuleName
src/Language/PureScript/Errors.hs+1−1
@@ -758,7 +758,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
758758
759759 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
760760 paras [ line $ "The import of module " ++ markCode (runModuleName mn) ++ " contains the following unused references:"
761− , indent $ paras $ map line names
761+ , indent $ paras $ map (line . markCode . runName . Qualified Nothing) names
762762 , line "It could be replaced with:"
763763 , indent $ line $ markCode $ showSuggestion msg ]
764764
src/Language/PureScript/Linter/Imports.hs+12−12
@@ -243,7 +243,7 @@ lintImportDecl env mni qualifierName names declType allowImplicit =
243243 didWarn' <- forM (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
244244 let allCtors = dctorsForType mni tn
245245 -- 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) $
247247 case (c, dctors `intersect` allCtors) of
248248 (_, []) | c /= Just [] -> warn (UnusedDctorImport mni tn qualifierName allRefs)
249249 (Just ctors, dctors') ->
@@ -335,18 +335,18 @@ findUsedRefs env mni qn names =
335335matchName
336336 :: (ProperName 'ConstructorName -> Maybe (ProperName 'TypeName))
337337 -> Name
338− -> Maybe String
339−matchName _ (IdentName x) = Just $ showIdent 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
344−
345−runDeclRef :: DeclarationRef -> Maybe String
338+ -> Maybe Name
339+matchName lookupDc (DctorName x) = TyName <$> lookupDc x
340+matchName _ ModName{} = Nothing
341+matchName _ name = Just name
342+
343+runDeclRef :: DeclarationRef -> Maybe Name
346344runDeclRef (PositionedDeclarationRef _ _ ref) = runDeclRef ref
347−runDeclRef (ValueRef ident) = Just $ showIdent ident
348−runDeclRef (TypeRef pn _) = Just $ runProperName pn
349−runDeclRef (TypeClassRef pn) = Just $ runProperName pn
345+runDeclRef (ValueRef ident) = Just $ IdentName ident
346+runDeclRef (ValueOpRef op) = Just $ ValOpName op
347+runDeclRef (TypeRef pn _) = Just $ TyName pn
348+runDeclRef (TypeOpRef op) = Just $ TyOpName op
349+runDeclRef (TypeClassRef pn) = Just $ TyClassName pn
350350runDeclRef _ = Nothing
351351
352352checkDuplicateImports