git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2073 from LiamGoodacre/update/remove-deprecated-class-syntax
a9dd375Gary Burgess
examples/docs/src/TypeClassWithoutMembers.purs+1−1
@@ -8,4 +8,4 @@ module Intermediate
8 ( module SomeTypeClass )
8 ( module SomeTypeClass )
9 where
9 where
10
10
11−import SomeTypeClass (SomeClass)
11+import SomeTypeClass (class SomeClass)
examples/failing/MissingClassMemberExport.purs+1−1
@@ -1,5 +1,5 @@
1-- @shouldFailWith TransitiveExportError
1-- @shouldFailWith TransitiveExportError
2−module Test (Foo) where
2+module Test (class Foo) where
3
3
4import Prelude
4import Prelude
5
5
examples/passing/ImportHiding.purs+1−1
@@ -3,7 +3,7 @@ module Main where
3import Control.Monad.Eff.Console
3import Control.Monad.Eff.Console
4import Prelude hiding (
4import Prelude hiding (
5 show, -- a value
5 show, -- a value
6− Show, -- a type class
6+ class Show, -- a type class
7 Unit(..) -- a constructor
7 Unit(..) -- a constructor
8 )
8 )
9
9
psci/PSCi.hs−1
@@ -256,7 +256,6 @@ handleShowImportedModules = do
256 showRef (P.TypeOpRef ident) = "type (" ++ N.runIdent ident ++ ")"
256 showRef (P.TypeOpRef ident) = "type (" ++ N.runIdent ident ++ ")"
257 showRef (P.ValueRef ident) = N.runIdent ident
257 showRef (P.ValueRef ident) = N.runIdent ident
258 showRef (P.TypeClassRef pn) = "class " ++ N.runProperName pn
258 showRef (P.TypeClassRef pn) = "class " ++ N.runProperName pn
259− showRef (P.ProperRef pn) = pn
260 showRef (P.TypeInstanceRef ident) = N.runIdent ident
259 showRef (P.TypeInstanceRef ident) = N.runIdent ident
261 showRef (P.ModuleRef name) = "module " ++ N.runModuleName name
260 showRef (P.ModuleRef name) = "module " ++ N.runModuleName name
262 showRef (P.PositionedDeclarationRef _ _ ref) = showRef ref
261 showRef (P.PositionedDeclarationRef _ _ ref) = showRef ref
src/Language/PureScript/AST/Declarations.hs−5
@@ -82,10 +82,6 @@ data DeclarationRef
82 --
82 --
83 | ModuleRef ModuleName
83 | ModuleRef ModuleName
84 -- |
84 -- |
85− -- An unspecified ProperName ref. This will be replaced with a TypeClassRef
86− -- or TypeRef during name desugaring.
87− | ProperRef String
88− -- |
89 -- A declaration reference with source position information
85 -- A declaration reference with source position information
90 --
86 --
91 | PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
87 | PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
@@ -98,7 +94,6 @@ instance Eq DeclarationRef where
98 (TypeClassRef name) == (TypeClassRef name') = name == name'
94 (TypeClassRef name) == (TypeClassRef name') = name == name'
99 (TypeInstanceRef name) == (TypeInstanceRef name') = name == name'
95 (TypeInstanceRef name) == (TypeInstanceRef name') = name == name'
100 (ModuleRef name) == (ModuleRef name') = name == name'
96 (ModuleRef name) == (ModuleRef name') = name == name'
101− (ProperRef name) == (ProperRef name') = name == name'
102 (PositionedDeclarationRef _ _ r) == r' = r == r'
97 (PositionedDeclarationRef _ _ r) == r' = r == r'
103 r == (PositionedDeclarationRef _ _ r') = r == r'
98 r == (PositionedDeclarationRef _ _ r') = r == r'
104 _ == _ = False
99 _ == _ = False
src/Language/PureScript/AST/Exported.hs−3
@@ -132,9 +132,6 @@ isExported (Just exps) decl = any (matches decl) exps
132 matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'
132 matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'
133 matches (TypeClassDeclaration ident _ _ _) (TypeClassRef ident') = ident == ident'
133 matches (TypeClassDeclaration ident _ _ _) (TypeClassRef ident') = ident == ident'
134
134
135− matches (DataDeclaration _ ident _ _) (ProperRef ident') = runProperName ident == ident'
136− matches (TypeClassDeclaration ident _ _ _) (ProperRef ident') = runProperName ident == ident'
137−
138 matches (FixityDeclaration _ name (Just (Qualified _ (AliasValue _)))) (ValueRef ident') = name == runIdent ident'
135 matches (FixityDeclaration _ name (Just (Qualified _ (AliasValue _)))) (ValueRef ident') = name == runIdent ident'
139 matches (FixityDeclaration _ name (Just (Qualified _ (AliasConstructor _)))) (ValueRef ident') = name == runIdent ident'
136 matches (FixityDeclaration _ name (Just (Qualified _ (AliasConstructor _)))) (ValueRef ident') = name == runIdent ident'
140 matches (FixityDeclaration _ name (Just (Qualified _ (AliasType _)))) (TypeOpRef ident') = name == runIdent ident'
137 matches (FixityDeclaration _ name (Just (Qualified _ (AliasType _)))) (TypeOpRef ident') = name == runIdent ident'
src/Language/PureScript/Errors.hs−22
@@ -141,8 +141,6 @@ data SimpleErrorMessage
141 | UnusedDctorImport (ProperName 'TypeName)
141 | UnusedDctorImport (ProperName 'TypeName)
142 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
142 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
143 | DeprecatedOperatorDecl String
143 | DeprecatedOperatorDecl String
144− | DeprecatedClassImport ModuleName (ProperName 'ClassName)
145− | DeprecatedClassExport (ProperName 'ClassName)
146 | DuplicateSelectiveImport ModuleName
144 | DuplicateSelectiveImport ModuleName
147 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
145 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
148 | DuplicateImportRef String
146 | DuplicateImportRef String
@@ -328,8 +326,6 @@ errorCode em = case unwrapErrorMessage em of
328 UnusedDctorImport{} -> "UnusedDctorImport"
326 UnusedDctorImport{} -> "UnusedDctorImport"
329 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
327 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
330 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
328 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
331− DeprecatedClassImport{} -> "DeprecatedClassImport"
332− DeprecatedClassExport{} -> "DeprecatedClassExport"
333 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
329 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
334 DuplicateImport{} -> "DuplicateImport"
330 DuplicateImport{} -> "DuplicateImport"
335 DuplicateImportRef{} -> "DuplicateImportRef"
331 DuplicateImportRef{} -> "DuplicateImportRef"
@@ -453,7 +449,6 @@ wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ error
453-- TODO Other possible suggestions:
449-- TODO Other possible suggestions:
454-- WildcardInferredType - source span not small enough
450-- WildcardInferredType - source span not small enough
455-- DuplicateSelectiveImport - would require 2 ranges to remove and 1 insert
451-- DuplicateSelectiveImport - would require 2 ranges to remove and 1 insert
456−-- DeprecatedClassExport, DeprecatedClassImport, would want to replace smaller span?
457errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
452errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
458errorSuggestion err = case err of
453errorSuggestion err = case err of
459 UnusedImport{} -> emptySuggestion
454 UnusedImport{} -> emptySuggestion
@@ -934,22 +929,6 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
934 , line "Support for value-declared operators will be removed in PureScript 0.9."
929 , line "Support for value-declared operators will be removed in PureScript 0.9."
935 ]
930 ]
936
931
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−
953 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
932 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
954 line $ "There is an existing import of " ++ runModuleName name ++ ", consider merging the import lists"
933 line $ "There is an existing import of " ++ runModuleName name ++ ", consider merging the import lists"
955
934
@@ -1208,7 +1187,6 @@ prettyPrintRef (TypeRef pn (Just dctors)) = runProperName pn ++ "(" ++ intercala
1208prettyPrintRef (TypeOpRef ident) = "type " ++ showIdent ident
1187prettyPrintRef (TypeOpRef ident) = "type " ++ showIdent ident
1209prettyPrintRef (ValueRef ident) = showIdent ident
1188prettyPrintRef (ValueRef ident) = showIdent ident
1210prettyPrintRef (TypeClassRef pn) = "class " ++ runProperName pn
1189prettyPrintRef (TypeClassRef pn) = "class " ++ runProperName pn
1211−prettyPrintRef (ProperRef name) = name
1212prettyPrintRef (TypeInstanceRef ident) = showIdent ident
1190prettyPrintRef (TypeInstanceRef ident) = showIdent ident
1213prettyPrintRef (ModuleRef name) = "module " ++ runModuleName name
1191prettyPrintRef (ModuleRef name) = "module " ++ runModuleName name
1214prettyPrintRef (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
1192prettyPrintRef (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
src/Language/PureScript/Ide/Imports.hs+1−8
@@ -233,10 +233,8 @@ addExplicitImport' decl moduleName imports =
233 insertDeclIntoRefs (DataConstructor dtor tn _) refs =
233 insertDeclIntoRefs (DataConstructor dtor tn _) refs =
234 let
234 let
235 dtor' = P.ProperName (T.unpack dtor)
235 dtor' = P.ProperName (T.unpack dtor)
236− -- TODO: Get rid of this once typeclasses can't be imported like types
237− refs' = properRefToTypeRef <$> refs
238 in
236 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
240 insertDeclIntoRefs dr refs = List.nubBy ((==) `on` P.prettyPrintRef) (refFromDeclaration dr : refs)
238 insertDeclIntoRefs dr refs = List.nubBy ((==) `on` P.prettyPrintRef) (refFromDeclaration dr : refs)
241
239
242 insertDtor dtor (P.TypeRef tn' dtors) =
240 insertDtor dtor (P.TypeRef tn' dtors) =
@@ -247,11 +245,6 @@ addExplicitImport' decl moduleName imports =
247 Nothing -> P.TypeRef tn' Nothing
245 Nothing -> P.TypeRef tn' Nothing
248 insertDtor _ refs = refs
246 insertDtor _ refs = refs
249
247
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−
255 matchType :: P.ProperName 'P.TypeName -> P.DeclarationRef -> Bool
248 matchType :: P.ProperName 'P.TypeName -> P.DeclarationRef -> Bool
256 matchType tn (P.TypeRef n _) = tn == n
249 matchType tn (P.TypeRef n _) = tn == n
257 matchType _ _ = False
250 matchType _ _ = False
src/Language/PureScript/Parser/Declarations.hs+3−3
@@ -154,15 +154,15 @@ parseDeclarationRef :: TokenParser DeclarationRef
154parseDeclarationRef =
154parseDeclarationRef =
155 withSourceSpan PositionedDeclarationRef
155 withSourceSpan PositionedDeclarationRef
156 $ (ValueRef <$> parseIdent)
156 $ (ValueRef <$> parseIdent)
157− <|> parseProperRef
157+ <|> parseTypeRef
158 <|> (TypeClassRef <$> (reserved "class" *> properName))
158 <|> (TypeClassRef <$> (reserved "class" *> properName))
159 <|> (ModuleRef <$> (indented *> reserved "module" *> moduleName))
159 <|> (ModuleRef <$> (indented *> reserved "module" *> moduleName))
160 <|> (TypeOpRef <$> (indented *> reserved "type" *> parens (Op <$> symbol)))
160 <|> (TypeOpRef <$> (indented *> reserved "type" *> parens (Op <$> symbol)))
161 where
161 where
162− parseProperRef = do
162+ parseTypeRef = do
163 name <- properName
163 name <- properName
164 dctors <- P.optionMaybe $ parens (symbol' ".." *> pure Nothing <|> Just <$> commaSep properName)
164 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)
166
166
167parseTypeClassDeclaration :: TokenParser Declaration
167parseTypeClassDeclaration :: TokenParser Declaration
168parseTypeClassDeclaration = do
168parseTypeClassDeclaration = do
src/Language/PureScript/Sugar/Names.hs+2−37
@@ -56,9 +56,8 @@ desugarImportsWithEnv
56 -> m (Env, [Module])
56 -> m (Env, [Module])
57desugarImportsWithEnv externs modules = do
57desugarImportsWithEnv externs modules = do
58 env <- silence $ foldM externsEnv primEnv externs
58 env <- silence $ foldM externsEnv primEnv externs
59− modules' <- traverse updateExportRefs modules
60− (modules'', env') <- first reverse <$> foldM updateEnv ([], env) modules'
59+ (modules', env') <- first reverse <$> foldM updateEnv ([], env) modules
61− (env',) <$> traverse (renameInModule' env') modules''
60+ (env',) <$> traverse (renameInModule' env') modules'
62 where
61 where
63 silence :: m a -> m a
62 silence :: m a -> m a
64 silence = censor (const mempty)
63 silence = censor (const mempty)
@@ -377,37 +376,3 @@ renameInModule env imports (Module ss coms mn decls exps) =
377 Nothing -> err
376 Nothing -> err
378 Just pos' -> rethrowWithPosition pos' err
377 Just pos' -> rethrowWithPosition pos' err
379 throwUnknown = throwError . errorMessage $ unknown qname
378 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
63resolveImports env (Module ss coms currentModule decls exps) =
63resolveImports env (Module ss coms currentModule decls exps) =
64 warnAndRethrow (addHint (ErrorInModule currentModule)) $ do
64 warnAndRethrow (addHint (ErrorInModule currentModule)) $ do
65
65
66− decls' <- traverse updateImportRef decls
67− imports <- findImports decls'
66+ imports <- findImports decls
68
67
69 for_ (M.toList imports) $ \(mn, imps) -> do
68 for_ (M.toList imports) $ \(mn, imps) -> do
70
69
@@ -97,7 +96,7 @@ resolveImports env (Module ss coms currentModule decls exps) =
97 scope = M.insert currentModule [(Nothing, Nothing, Nothing)] imports'
96 scope = M.insert currentModule [(Nothing, Nothing, Nothing)] imports'
98 resolved <- foldM (resolveModuleImport env) nullImports (M.toList scope)
97 resolved <- foldM (resolveModuleImport env) nullImports (M.toList scope)
99
98
100− return (Module ss coms currentModule decls' exps, resolved)
99+ return (Module ss coms currentModule decls exps, resolved)
101
100
102 where
101 where
103 defQual :: ImportDef -> Maybe ModuleName
102 defQual :: ImportDef -> Maybe ModuleName
@@ -133,29 +132,6 @@ resolveImports env (Module ss coms currentModule decls exps) =
133 warn :: Maybe SourceSpan -> SimpleErrorMessage -> m ()
132 warn :: Maybe SourceSpan -> SimpleErrorMessage -> m ()
134 warn pos msg = maybe id warnWithPosition pos $ tell . errorMessage $ msg
133 warn pos msg = maybe id warnWithPosition pos $ tell . errorMessage $ msg
135
134
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−
159-- | Constructs a set of imports for a single module import.
135-- | Constructs a set of imports for a single module import.
160resolveModuleImport
136resolveModuleImport
161 :: forall m
137 :: forall m