Commit ff8cd2c5 authored by simonpj's avatar simonpj

[project @ 2002-12-10 17:34:34 by simonpj]

Check for qualified names in binding positions in the parser instead
of the rename.  In External Core it's OK to have qualified names in
these places.
parent 449a83af
......@@ -92,7 +92,7 @@ module RdrHsSyn (
import HsSyn -- Lots of it
import RdrName ( RdrName, isRdrTyVar, mkRdrUnqual, mkUnqual, rdrNameOcc,
isRdrTyVar, isRdrDataCon, isUnqual, getRdrName,
isRdrTyVar, isRdrDataCon, isUnqual, getRdrName, isQual,
setRdrNameSpace )
import BasicTypes ( RecFlag(..), FixitySig(..), maxPrecedence )
import Class ( DefMeth (..) )
......@@ -612,8 +612,9 @@ checkPat (HsApp f x) args =
checkPat x [] `thenP` \x ->
checkPat f (x:args)
checkPat e [] = case e of
EWildPat -> returnP (WildPat placeHolderType)
HsVar x -> returnP (VarPat x)
EWildPat -> returnP (WildPat placeHolderType)
HsVar x | isQual x -> parseError ("Qualified variable in pattern: " ++ showRdrName x)
| otherwise -> returnP (VarPat x)
HsLit l -> returnP (LitPat l)
HsOverLit l -> returnP (NPatIn l Nothing)
ELazyPat e -> checkPat e [] `thenP` (returnP . LazyPat)
......@@ -684,8 +685,11 @@ checkValDef
checkValDef lhs opt_sig grhss loc
= case isFunLhs lhs [] of
Just (f,inf,es) ->
checkPatterns loc es `thenP` \ps ->
Just (f,inf,es)
| isQual f
-> parseError ("Qualified name in function definition: " ++ showRdrName f)
| otherwise
-> checkPatterns loc es `thenP` \ps ->
returnP (RdrValBinding (FunMonoBind f inf [Match ps opt_sig grhss] loc))
Nothing ->
......@@ -862,6 +866,9 @@ mkIfaceExports decls = map getExport decls
-- Misc utils
\begin{code}
showRdrName :: RdrName -> String
showRdrName r = showSDoc (ppr r)
parseError :: String -> P a
parseError s =
getSrcLocP `thenP` \ loc ->
......
......@@ -233,14 +233,11 @@ lookupTopBndrRn rdr_name
-- A separate function (importsFromLocalDecls) reports duplicate top level
-- decls, so here it's safe just to choose an arbitrary one.
-- There should never be a qualified name in a binding position
-- The parser could check this, but doesn't (yet)
| isQual rdr_name
= getSrcLocM `thenM` \ loc ->
qualNameErr (text "In its declaration") (rdr_name,loc) `thenM_`
returnM (mkUnboundName rdr_name)
-- There should never be a qualified name in a binding position in Haskell,
-- but there can be if we have read in an external-Core file.
-- The Haskell parser checks for the illegal qualified name, so we
-- don't need to do so here.
| otherwise
= ASSERT( not (isOrig rdr_name) )
-- Original names are used only for occurrences,
-- not binding sites
......@@ -338,15 +335,12 @@ lookupInstDeclBndr cls_name rdr_name
other -> pprPanic "lookupInstDeclBndr" (ppr cls_name)
| isQual rdr_name -- Should never have a qualified name in a binding position
= getSrcLocM `thenM` \ loc ->
qualNameErr (text "In an instance method") (rdr_name,loc) `thenM_`
returnM (mkUnboundName rdr_name)
| otherwise -- Occurs in derived instances, where we just
-- refer directly to the right method, and avail_env
-- isn't available
= ASSERT2( not (isQual rdr_name), ppr rdr_name )
-- NB: qualified names are rejected by the parser
lookupOrigName rdr_name
where
......@@ -832,7 +826,9 @@ checkDupOrQualNames, checkDupNames :: SDoc
-- Works in any variant of the renamer monad
checkDupOrQualNames doc_str rdr_names_w_loc
= -- Check for use of qualified names
= -- Qualified names in patterns are now rejected by the parser
-- but I'm not 100% certain that it finds all cases, so I've left
-- this check in for now. Should go eventually.
mappM_ (qualNameErr doc_str) quals `thenM_`
checkDupNames doc_str rdr_names_w_loc
where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment