summaryrefslogtreecommitdiff
path: root/compiler/hsSyn
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2014-04-04 08:41:35 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2014-04-04 08:46:21 +0100
commit750271e61bdbaad50c19176406512e79abe404a8 (patch)
tree610cce20fd4ac7cb3259617744b42a84a3c7b241 /compiler/hsSyn
parente94ed11a09befd8a83e21b68cb3d492a6f7a8986 (diff)
downloadhaskell-750271e61bdbaad50c19176406512e79abe404a8.tar.gz
Simplify and tidy up the handling of tuple names
This fixes Trac #8954. There were actually three places where tuple occ-names were parsed: - IfaceEnv.lookupOrigNameCache - Convert.isBuiltInOcc - OccName.isTupleOcc_maybe I combined all three into TysWiredIn.isBuiltInOcc_maybe Much nicer.
Diffstat (limited to 'compiler/hsSyn')
-rw-r--r--compiler/hsSyn/Convert.lhs25
1 files changed, 4 insertions, 21 deletions
diff --git a/compiler/hsSyn/Convert.lhs b/compiler/hsSyn/Convert.lhs
index 0ec91ec1c3..69d2bd012d 100644
--- a/compiler/hsSyn/Convert.lhs
+++ b/compiler/hsSyn/Convert.lhs
@@ -1108,8 +1108,10 @@ thRdrName loc ctxt_ns th_occ th_name
TH.NameQ mod -> (mkRdrQual $! mk_mod mod) $! occ
TH.NameL uniq -> nameRdrName $! (((Name.mkInternalName $! mk_uniq uniq) $! occ) loc)
TH.NameU uniq -> nameRdrName $! (((Name.mkSystemNameAt $! mk_uniq uniq) $! occ) loc)
- TH.NameS | Just name <- isBuiltInOcc ctxt_ns th_occ -> nameRdrName $! name
- | otherwise -> mkRdrUnqual $! occ
+ TH.NameS | Just name <- isBuiltInOcc_maybe occ -> nameRdrName $! name
+ | otherwise -> mkRdrUnqual $! occ
+ -- We check for built-in syntax here, because the TH
+ -- user might have written a (NameS "(,,)"), for example
where
occ :: OccName.OccName
occ = mk_occ ctxt_ns th_occ
@@ -1129,25 +1131,6 @@ thRdrNameGuesses (TH.Name occ flavour)
| otherwise = [OccName.varName, OccName.tvName]
occ_str = TH.occString occ
-isBuiltInOcc :: OccName.NameSpace -> String -> Maybe Name.Name
--- Built in syntax isn't "in scope" so an Unqual RdrName won't do
--- We must generate an Exact name, just as the parser does
-isBuiltInOcc ctxt_ns occ
- = case occ of
- ":" -> Just (Name.getName consDataCon)
- "[]" -> Just (Name.getName nilDataCon)
- "()" -> Just (tup_name 0)
- '(' : ',' : rest -> go_tuple 2 rest
- _ -> Nothing
- where
- go_tuple n ")" = Just (tup_name n)
- go_tuple n (',' : rest) = go_tuple (n+1) rest
- go_tuple _ _ = Nothing
-
- tup_name n
- | OccName.isTcClsNameSpace ctxt_ns = Name.getName (tupleTyCon BoxedTuple n)
- | otherwise = Name.getName (tupleCon BoxedTuple n)
-
-- The packing and unpacking is rather turgid :-(
mk_occ :: OccName.NameSpace -> String -> OccName.OccName
mk_occ ns occ = OccName.mkOccName ns occ