git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2073 from LiamGoodacre/update/remove-deprecated-class-syntax

0.9 Remove deprecated class import/export syntax

commita9dd37588ea35e7734971cca6a00d94648d30815 authorGary Burgess <gary.burgess@gmail.com> dateMon 2 May 2016, 17:52 (10 years ago) parent87074a4d9cdd8f
11 files changed+11−108
examples/docs/src/TypeClassWithoutMembers.purs+1−1 examples/failing/MissingClassMemberExport.purs+1−1 examples/passing/ImportHiding.purs+1−1 psci/PSCi.hs−1 src/Language/PureScript/AST/Declarations.hs−5 src/Language/PureScript/AST/Exported.hs−3 src/Language/PureScript/Errors.hs−22 src/Language/PureScript/Ide/Imports.hs+1−8 src/Language/PureScript/Parser/Declarations.hs+3−3 src/Language/PureScript/Sugar/Names.hs+2−37 src/Language/PureScript/Sugar/Names/Imports.hs+2−26
examples/docs/src/TypeClassWithoutMembers.purs+1−1
@@ -8,4 +8,4 @@ module Intermediate
88 ( module SomeTypeClass )
99 where
1010
11−import SomeTypeClass (SomeClass)
11+import SomeTypeClass (class SomeClass)
examples/failing/MissingClassMemberExport.purs+1−1
@@ -1,5 +1,5 @@
11-- @shouldFailWith TransitiveExportError
2−module Test (Foo) where
2+module Test (class Foo) where
33
44import Prelude
55
examples/passing/ImportHiding.purs+1−1
@@ -3,7 +3,7 @@ module Main where
33import Control.Monad.Eff.Console
44import Prelude hiding (
55 show, -- a value
6− Show, -- a type class
6+ class Show, -- a type class
77 Unit(..) -- a constructor
88 )
99
psci/PSCi.hs−1
@@ -256,7 +256,6 @@ handleShowImportedModules = do
256256 showRef (P.TypeOpRef ident) = "type (" ++ N.runIdent ident ++ ")"
257257 showRef (P.ValueRef ident) = N.runIdent ident
258258 showRef (P.TypeClassRef pn) = "class " ++ N.runProperName pn
259− showRef (P.ProperRef pn) = pn
260259 showRef (P.TypeInstanceRef ident) = N.runIdent ident
261260 showRef (P.ModuleRef name) = "module " ++ N.runModuleName name
262261 showRef (P.PositionedDeclarationRef _ _ ref) = showRef ref
src/Language/PureScript/AST/Declarations.hs−5
@@ -82,10 +82,6 @@ data DeclarationRef
8282 --
8383 | ModuleRef ModuleName
8484 -- |
85− -- An unspecified ProperName ref. This will be replaced with a TypeClassRef
86− -- or TypeRef during name desugaring.
87− | ProperRef String
88− -- |
8985 -- A declaration reference with source position information
9086 --
9187 | PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
@@ -98,7 +94,6 @@ instance Eq DeclarationRef where
9894 (TypeClassRef name) == (TypeClassRef name') = name == name'
9995 (TypeInstanceRef name) == (TypeInstanceRef name') = name == name'
10096 (ModuleRef name) == (ModuleRef name') = name == name'
101− (ProperRef name) == (ProperRef name') = name == name'
10297 (PositionedDeclarationRef _ _ r) == r' = r == r'
10398 r == (PositionedDeclarationRef _ _ r') = r == r'
10499 _ == _ = False
src/Language/PureScript/AST/Exported.hs−3
@@ -132,9 +132,6 @@ isExported (Just exps) decl = any (matches decl) exps
132132 matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'
133133 matches (TypeClassDeclaration ident _ _ _) (TypeClassRef ident') = ident == ident'
134134
135− matches (DataDeclaration _ ident _ _) (ProperRef ident') = runProperName ident == ident'
136− matches (TypeClassDeclaration ident _ _ _) (ProperRef ident') = runProperName ident == ident'
137−
138135 matches (FixityDeclaration _ name (Just (Qualified _ (AliasValue _)))) (ValueRef ident') = name == runIdent ident'
139136 matches (FixityDeclaration _ name (Just (Qualified _ (AliasConstructor _)))) (ValueRef ident') = name == runIdent ident'
140137 matches (FixityDeclaration _ name (Just (Qualified _ (AliasType _)))) (TypeOpRef ident') = name == runIdent ident'
src/Language/PureScript/Errors.hs−22
@@ -141,8 +141,6 @@ data SimpleErrorMessage
141141 | UnusedDctorImport (ProperName 'TypeName)
142142 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
143143 | DeprecatedOperatorDecl String
144− | DeprecatedClassImport ModuleName (ProperName 'ClassName)
145− | DeprecatedClassExport (ProperName 'ClassName)
146144 | DuplicateSelectiveImport ModuleName
147145 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
148146 | DuplicateImportRef String
@@ -328,8 +326,6 @@ errorCode em = case unwrapErrorMessage em of
328326 UnusedDctorImport{} -> "UnusedDctorImport"
329327 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
330328 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
331− DeprecatedClassImport{} -> "DeprecatedClassImport"
332− DeprecatedClassExport{} -> "DeprecatedClassExport"
333329 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
334330 DuplicateImport{} -> "DuplicateImport"
335331 DuplicateImportRef{} -> "DuplicateImportRef"
@@ -453,7 +449,6 @@ wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ error
453449-- TODO Other possible suggestions:
454450-- WildcardInferredType - source span not small enough
455451-- DuplicateSelectiveImport - would require 2 ranges to remove and 1 insert
456−-- DeprecatedClassExport, DeprecatedClassImport, would want to replace smaller span?
457452errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
458453errorSuggestion err = case err of
459454 UnusedImport{} -> emptySuggestion
@@ -934,22 +929,6 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
934929 , line "Support for value-declared operators will be removed in PureScript 0.9."
935930 ]
936931
937− renderSimpleErrorMessage (DeprecatedClassImport mn name) =
938− paras [ line $ "Class import from " ++ runModuleName mn ++ " uses deprecated syntax that omits the 'class' keyword:"
939− , indent $ line $ runProperName name
940− , line "Should instead use the form:"
941− , indent $ line $ "class " ++ runProperName name
942− , line "The deprecated syntax will be removed in PureScript 0.9."
943− ]
944−
945− renderSimpleErrorMessage (DeprecatedClassExport name) =
946− paras [ line "Class export uses deprecated syntax that omits the 'class' keyword:"
947− , indent $ line $ runProperName name
948− , line "Should instead use the form:"
949− , indent $ line $ "class " ++ runProperName name
950− , line "The deprecated syntax will be removed in PureScript 0.9."
951− ]
952−
953932 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
954933 line $ "There is an existing import of " ++ runModuleName name ++ ", consider merging the import lists"
955934
@@ -1208,7 +1187,6 @@ prettyPrintRef (TypeRef pn (Just dctors)) = runProperName pn ++ "(" ++ intercala
12081187prettyPrintRef (TypeOpRef ident) = "type " ++ showIdent ident
12091188prettyPrintRef (ValueRef ident) = showIdent ident
12101189prettyPrintRef (TypeClassRef pn) = "class " ++ runProperName pn
1211−prettyPrintRef (ProperRef name) = name
12121190prettyPrintRef (TypeInstanceRef ident) = showIdent ident
12131191prettyPrintRef (ModuleRef name) = "module " ++ runModuleName name
12141192prettyPrintRef (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
src/Language/PureScript/Ide/Imports.hs+1−8
@@ -233,10 +233,8 @@ addExplicitImport' decl moduleName imports =
233233 insertDeclIntoRefs (DataConstructor dtor tn _) refs =
234234 let
235235 dtor' = P.ProperName (T.unpack dtor)
236− -- TODO: Get rid of this once typeclasses can't be imported like types
237− refs' = properRefToTypeRef <$> refs
238236 in
239− updateAtFirstOrPrepend (matchType tn) (insertDtor dtor') (P.TypeRef tn (Just [dtor'])) refs'
237+ updateAtFirstOrPrepend (matchType tn) (insertDtor dtor') (P.TypeRef tn (Just [dtor'])) refs
240238 insertDeclIntoRefs dr refs = List.nubBy ((==) `on` P.prettyPrintRef) (refFromDeclaration dr : refs)
241239
242240 insertDtor dtor (P.TypeRef tn' dtors) =
@@ -247,11 +245,6 @@ addExplicitImport' decl moduleName imports =
247245 Nothing -> P.TypeRef tn' Nothing
248246 insertDtor _ refs = refs
249247
250−
251− -- TODO: Get rid of this once typeclasses can't be imported like types
252− properRefToTypeRef (P.ProperRef n) = P.TypeRef (P.ProperName n) (Just [])
253− properRefToTypeRef r = r
254−
255248 matchType :: P.ProperName 'P.TypeName -> P.DeclarationRef -> Bool
256249 matchType tn (P.TypeRef n _) = tn == n
257250 matchType _ _ = False
src/Language/PureScript/Parser/Declarations.hs+3−3
@@ -154,15 +154,15 @@ parseDeclarationRef :: TokenParser DeclarationRef
154154parseDeclarationRef =
155155 withSourceSpan PositionedDeclarationRef
156156 $ (ValueRef <$> parseIdent)
157− <|> parseProperRef
157+ <|> parseTypeRef
158158 <|> (TypeClassRef <$> (reserved "class" *> properName))
159159 <|> (ModuleRef <$> (indented *> reserved "module" *> moduleName))
160160 <|> (TypeOpRef <$> (indented *> reserved "type" *> parens (Op <$> symbol)))
161161 where
162− parseProperRef = do
162+ parseTypeRef = do
163163 name <- properName
164164 dctors <- P.optionMaybe $ parens (symbol' ".." *> pure Nothing <|> Just <$> commaSep properName)
165− return $ maybe (ProperRef (runProperName name)) (TypeRef name) dctors
165+ return $ TypeRef name (fromMaybe (Just []) dctors)
166166
167167parseTypeClassDeclaration :: TokenParser Declaration
168168parseTypeClassDeclaration = do
src/Language/PureScript/Sugar/Names.hs+2−37
@@ -56,9 +56,8 @@ desugarImportsWithEnv
5656 -> m (Env, [Module])
5757desugarImportsWithEnv externs modules = do
5858 env <- silence $ foldM externsEnv primEnv externs
59− modules' <- traverse updateExportRefs modules
60− (modules'', env') <- first reverse <$> foldM updateEnv ([], env) modules'
61− (env',) <$> traverse (renameInModule' env') modules''
59+ (modules', env') <- first reverse <$> foldM updateEnv ([], env) modules
60+ (env',) <$> traverse (renameInModule' env') modules'
6261 where
6362 silence :: m a -> m a
6463 silence = censor (const mempty)
@@ -377,37 +376,3 @@ renameInModule env imports (Module ss coms mn decls exps) =
377376 Nothing -> err
378377 Just pos' -> rethrowWithPosition pos' err
379378 throwUnknown = throwError . errorMessage $ unknown qname
380−
381−-- |
382−-- Replaces `ProperRef` export values with a `TypeRef` or `TypeClassRef`
383−-- depending on what is availble within the module. Warns when a `ProperRef`
384−-- desugars into a `TypeClassRef`.
385−--
386−updateExportRefs
387− :: forall m
388− . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
389− => Module
390− -> m Module
391−updateExportRefs (Module ss coms mn decls exps) =
392− Module ss coms mn decls <$> traverse (traverse updateRef) exps
393− where
394−
395− updateRef :: DeclarationRef -> m DeclarationRef
396− updateRef (ProperRef name)
397− | ProperName name `elem` classNames = do
398− tell . errorMessage . DeprecatedClassExport $ ProperName name
399− return . TypeClassRef $ ProperName name
400− -- Fall through case here - assume it's a type if it's not a class.
401− -- If it's a reference to something that doesn't actually exist it will
402− -- be picked up elsewhere
403− | otherwise = return $ TypeRef (ProperName name) (Just [])
404− updateRef (PositionedDeclarationRef pos com ref) =
405− warnWithPosition pos $ PositionedDeclarationRef pos com <$> updateRef ref
406− updateRef other = return other
407−
408− classNames :: [ProperName 'ClassName]
409− classNames = mapMaybe go decls
410− where
411− go (PositionedDeclaration _ _ d) = go d
412− go (TypeClassDeclaration name _ _ _) = Just name
413− go _ = Nothing
src/Language/PureScript/Sugar/Names/Imports.hs+2−26
@@ -63,8 +63,7 @@ resolveImports
6363resolveImports env (Module ss coms currentModule decls exps) =
6464 warnAndRethrow (addHint (ErrorInModule currentModule)) $ do
6565
66− decls' <- traverse updateImportRef decls
67− imports <- findImports decls'
66+ imports <- findImports decls
6867
6968 for_ (M.toList imports) $ \(mn, imps) -> do
7069
@@ -97,7 +96,7 @@ resolveImports env (Module ss coms currentModule decls exps) =
9796 scope = M.insert currentModule [(Nothing, Nothing, Nothing)] imports'
9897 resolved <- foldM (resolveModuleImport env) nullImports (M.toList scope)
9998
100− return (Module ss coms currentModule decls' exps, resolved)
99+ return (Module ss coms currentModule decls exps, resolved)
101100
102101 where
103102 defQual :: ImportDef -> Maybe ModuleName
@@ -133,29 +132,6 @@ resolveImports env (Module ss coms currentModule decls exps) =
133132 warn :: Maybe SourceSpan -> SimpleErrorMessage -> m ()
134133 warn pos msg = maybe id warnWithPosition pos $ tell . errorMessage $ msg
135134
136− updateImportRef :: Declaration -> m Declaration
137− updateImportRef (PositionedDeclaration pos com d) =
138− warnAndRethrowWithPosition pos $ PositionedDeclaration pos com <$> updateImportRef d
139− updateImportRef (ImportDeclaration mn typ qual) = do
140− modExports <- getExports env mn
141− typ' <- case typ of
142− Implicit -> return Implicit
143− Explicit refs -> Explicit <$> updateProperRef mn modExports `traverse` refs
144− Hiding refs -> Hiding <$> updateProperRef mn modExports `traverse` refs
145− return $ ImportDeclaration mn typ' qual
146− updateImportRef other = return other
147−
148− updateProperRef :: ModuleName -> Exports -> DeclarationRef -> m DeclarationRef
149− updateProperRef importModule modExports (ProperRef name) =
150− if ProperName name `elem` (fst `map` exportedTypeClasses modExports)
151− then do
152− tell . errorMessage $ DeprecatedClassImport importModule (ProperName name)
153− return . TypeClassRef $ ProperName name
154− else return $ TypeRef (ProperName name) (Just [])
155− updateProperRef importModule modExports (PositionedDeclarationRef pos com ref) =
156− PositionedDeclarationRef pos com <$> updateProperRef importModule modExports ref
157− updateProperRef _ _ other = return other
158−
159135-- | Constructs a set of imports for a single module import.
160136resolveModuleImport
161137 :: forall m