Skip to content

Commit d9cdd8f

Browse files
committed
0.9 Remove deprecated class import/export syntax
1 parent bd7ac4f commit d9cdd8f

File tree

11 files changed

+11
-108
lines changed

11 files changed

+11
-108
lines changed

examples/docs/src/TypeClassWithoutMembers.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- @shouldFailWith TransitiveExportError
2-
module Test (Foo) where
2+
module Test (class Foo) where
33

44
import Prelude
55

examples/passing/ImportHiding.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Main where
33
import Control.Monad.Eff.Console
44
import 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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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?
457452
errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
458453
errorSuggestion 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
12081187
prettyPrintRef (TypeOpRef ident) = "type " ++ showIdent ident
12091188
prettyPrintRef (ValueRef ident) = showIdent ident
12101189
prettyPrintRef (TypeClassRef pn) = "class " ++ runProperName pn
1211-
prettyPrintRef (ProperRef name) = name
12121190
prettyPrintRef (TypeInstanceRef ident) = showIdent ident
12131191
prettyPrintRef (ModuleRef name) = "module " ++ runModuleName name
12141192
prettyPrintRef (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref

src/Language/PureScript/Ide/Imports.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ parseDeclarationRef :: TokenParser DeclarationRef
154154
parseDeclarationRef =
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

167167
parseTypeClassDeclaration :: TokenParser Declaration
168168
parseTypeClassDeclaration = do

src/Language/PureScript/Sugar/Names.hs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ desugarImportsWithEnv
5656
-> m (Env, [Module])
5757
desugarImportsWithEnv 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

0 commit comments

Comments
 (0)