git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1772 from purescript/warn-unspecified-constructors
3bec40cGary Burgess
src/Language/PureScript/Errors.hs+7
@@ -139,6 +139,7 @@ data SimpleErrorMessage
139 | IntOutOfRange Integer String Integer Integer
139 | IntOutOfRange Integer String Integer Integer
140 | RedundantEmptyHidingImport ModuleName
140 | RedundantEmptyHidingImport ModuleName
141 | ImplicitImport ModuleName [DeclarationRef]
141 | ImplicitImport ModuleName [DeclarationRef]
142+ | ImplicitDctorImport ProperName [ProperName]
142 | CaseBinderLengthDiffers Int [Binder]
143 | CaseBinderLengthDiffers Int [Binder]
143 deriving (Show)
144 deriving (Show)
144
145
@@ -310,6 +311,7 @@ errorCode em = case unwrapErrorMessage em of
310 IntOutOfRange{} -> "IntOutOfRange"
311 IntOutOfRange{} -> "IntOutOfRange"
311 RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
312 RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
312 ImplicitImport{} -> "ImplicitImport"
313 ImplicitImport{} -> "ImplicitImport"
314+ ImplicitDctorImport{} -> "ImplicitDctorImport"
313 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
315 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
314
316
315-- |
317-- |
@@ -859,6 +861,11 @@ prettyPrintSingleError full level e = flip evalState defaultUnknownMap $ do
859 , indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
861 , indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
860 ]
862 ]
861
863
864+ renderSimpleErrorMessage (ImplicitDctorImport ty ctors) =
865+ paras [ line $ "Import of type " ++ runProperName ty ++ " has unspecified data constructors, consider using the explicit form: "
866+ , indent $ line $ runProperName ty ++ " (" ++ intercalate ", " (map runProperName ctors) ++ ")"
867+ ]
868+
862 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
869 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
863 paras $ [ line $ "Binder list length differs in case alternative:"
870 paras $ [ line $ "Binder list length differs in case alternative:"
864 , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
871 , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
src/Language/PureScript/Linter/Imports.hs+7−6
@@ -83,13 +83,14 @@ findUnusedImports (Module _ _ _ mdecls mexports) env usedImps = do
83 -- If we've not already warned a type is unused, check its data constructors
83 -- If we've not already warned a type is unused, check its data constructors
84 forM_ (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
84 forM_ (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
85 let allCtors = dctorsForType mni tn
85 let allCtors = dctorsForType mni tn
86− when (runProperName tn `elem` usedNames) $ case (c, null $ usedDctors `intersect` allCtors) of
86+ when (runProperName tn `elem` usedNames) $ case (c, usedDctors `intersect` allCtors) of
87− (Nothing, True) -> tell $ errorMessage $ UnusedDctorImport tn
87+ (_, []) ->
88− (Just (_:_), True) -> tell $ errorMessage $ UnusedDctorImport tn
88+ tell $ errorMessage $ UnusedDctorImport tn
89+ (Nothing, usedDctors') ->
90+ tell $ errorMessage $ ImplicitDctorImport tn usedDctors'
89− (Just ctors, _) ->
91+ (Just ctors, usedDctors') ->
90− let ddiff = ctors \\ usedDctors
92+ let ddiff = ctors \\ usedDctors'
91 in unless (null ddiff) $ tell $ errorMessage $ UnusedDctorExplicitImport tn ddiff
93 in unless (null ddiff) $ tell $ errorMessage $ UnusedDctorExplicitImport tn ddiff
92− _ -> return ()
93
94
94 return ()
95 return ()
95
96