summaryrefslogtreecommitdiff
path: root/compiler/parser/RdrHsSyn.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2016-05-10 08:41:46 +0200
committerBen Gamari <ben@smart-cactus.org>2016-05-10 12:02:14 +0200
commit53f26f5a45f146e1cc988bbcf76a362c877beaa2 (patch)
tree3f7c270f496f90fe3683f1536bea7ec13dd3dd9d /compiler/parser/RdrHsSyn.hs
parent3ca78062968f7ab6efff82122101e6f91b8c2cef (diff)
downloadhaskell-53f26f5a45f146e1cc988bbcf76a362c877beaa2.tar.gz
Forbid variables to be parents in import lists.
In the long discussion on #11432, it was decided that when a type constructor is parsed as a variable ((--.->) is one example) then in order to export the type constructor then the user should be required to use the ExplicitNamespaces keyword. This was implemented in quite an indirect manner in the renamer. It is much more direct to enforce this in the parser at the expense of slighty worse error messages. Further to this, the check in the renamer was actually slightly wrong. If the variable was in scope then no error was raised, this was causing panics, see #12026 for an example. Reviewers: austin, bgamari Subscribers: davean, skvadrik, thomie Differential Revision: https://phabricator.haskell.org/D2181 GHC Trac Issues: #12026
Diffstat (limited to 'compiler/parser/RdrHsSyn.hs')
-rw-r--r--compiler/parser/RdrHsSyn.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index 28ee4f07a0..c3f1d53d65 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -1387,10 +1387,10 @@ mkModuleImpExp n@(L l name) subs =
case subs of
ImpExpAbs
| isVarNameSpace (rdrNameSpace name) -> return $ IEVar n
- | otherwise -> return $ IEThingAbs (L l name)
- ImpExpAll -> return $ IEThingAll (L l name)
+ | otherwise -> IEThingAbs . L l <$> nameT
+ ImpExpAll -> IEThingAll . L l <$> nameT
ImpExpList xs ->
- return $ IEThingWith (L l name) NoIEWildcard xs []
+ (\newName -> IEThingWith (L l newName) NoIEWildcard xs []) <$> nameT
ImpExpAllWith xs ->
do allowed <- extension patternSynonymsEnabled
if allowed
@@ -1399,9 +1399,19 @@ mkModuleImpExp n@(L l name) subs =
pos = maybe NoIEWildcard IEWildcard
(findIndex isNothing withs)
ies = [L l n | L l (Just n) <- xs]
- in return (IEThingWith (L l name) pos ies [])
+ in (\newName -> IEThingWith (L l newName) pos ies []) <$> nameT
else parseErrorSDoc l
(text "Illegal export form (use PatternSynonyms to enable)")
+ where
+ nameT =
+ if isVarNameSpace (rdrNameSpace name)
+ then parseErrorSDoc l
+ (text "Expecting a type constructor but found a variable."
+ $$ if isSymOcc $ rdrNameOcc name
+ then text "If" <+> quotes (ppr name) <+> text "is a type constructor"
+ else empty
+ <+> text "then enable ExplicitNamespaces and use the 'type' keyword.")
+ else return $ name
mkTypeImpExp :: Located RdrName -- TcCls or Var name space
-> P (Located RdrName)