git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1772 from purescript/warn-unspecified-constructors

Warn about unspecified constructors in type imports

commit3bec40cfad9360d924986c500399a4da19634268 authorGary Burgess <gary.burgess@gmail.com> dateWed 30 Dec 2015, 01:48 (11 years ago) parent342c17f0c31b54
2 files changed+14−6
src/Language/PureScript/Errors.hs+7 src/Language/PureScript/Linter/Imports.hs+7−6
src/Language/PureScript/Errors.hs+7
@@ -139,6 +139,7 @@ data SimpleErrorMessage
139139 | IntOutOfRange Integer String Integer Integer
140140 | RedundantEmptyHidingImport ModuleName
141141 | ImplicitImport ModuleName [DeclarationRef]
142+ | ImplicitDctorImport ProperName [ProperName]
142143 | CaseBinderLengthDiffers Int [Binder]
143144 deriving (Show)
144145
@@ -310,6 +311,7 @@ errorCode em = case unwrapErrorMessage em of
310311 IntOutOfRange{} -> "IntOutOfRange"
311312 RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
312313 ImplicitImport{} -> "ImplicitImport"
314+ ImplicitDctorImport{} -> "ImplicitDctorImport"
313315 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
314316
315317-- |
@@ -859,6 +861,11 @@ prettyPrintSingleError full level e = flip evalState defaultUnknownMap $ do
859861 , indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
860862 ]
861863
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+
862869 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
863870 paras $ [ line $ "Binder list length differs in case alternative:"
864871 , 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
8383 -- If we've not already warned a type is unused, check its data constructors
8484 forM_ (mapMaybe getTypeRef declrefs) $ \(tn, c) -> do
8585 let allCtors = dctorsForType mni tn
86− when (runProperName tn `elem` usedNames) $ case (c, null $ usedDctors `intersect` allCtors) of
87− (Nothing, True) -> tell $ errorMessage $ UnusedDctorImport tn
88− (Just (_:_), True) -> tell $ errorMessage $ UnusedDctorImport tn
89− (Just ctors, _) ->
90− let ddiff = ctors \\ usedDctors
86+ when (runProperName tn `elem` usedNames) $ case (c, usedDctors `intersect` allCtors) of
87+ (_, []) ->
88+ tell $ errorMessage $ UnusedDctorImport tn
89+ (Nothing, usedDctors') ->
90+ tell $ errorMessage $ ImplicitDctorImport tn usedDctors'
91+ (Just ctors, usedDctors') ->
92+ let ddiff = ctors \\ usedDctors'
9193 in unless (null ddiff) $ tell $ errorMessage $ UnusedDctorExplicitImport tn ddiff
92− _ -> return ()
9394
9495 return ()
9596