summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2021-02-15 11:09:34 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2021-02-15 11:09:43 -0500
commitd1869cfcdee8a00a6c09e1d453ff0ece197b93c8 (patch)
tree483dd9ea5a3f660617bfaca195847f01bc80faa1 /compiler
parentb9fe4cd5ea843e95a333520e2e6036dd83852f5e (diff)
downloadhaskell-wip/T19374.tar.gz
Parse symbolic names in ANN type correctly with otyconwip/T19374
This adds a new `otycon` production to the parser that allows for type constructor names that are either alphanumeric (`tycon`) or symbolic (`tyconsym`), where the latter must be parenthesized appropriately. `otycon` is much like the existing `oqtycon` production, except that it does not permit qualified names. The parser now uses `otycon` to parse type constructor names in `ANN type` declarations, which fixes #19374. To make sure that all of this works, I added three test cases: * `should_compile/T19374a`: the original test case from #19374 * `should_fail/T19374b`: a test that makes sure that an `ANN` with a qualified name fails to parse * `should_fail/T19374c`: a test that makes sure that an `ANN type` with a qualified name fails to parse
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Parser.y8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index 4b165b1586..4018155d81 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -1921,7 +1921,7 @@ annotation :: { LHsDecl GhcPs }
(ValueAnnProvenance $2) $3))
[mo $1,mc $4] }
- | '{-# ANN' 'type' tycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 ->
+ | '{-# ANN' 'type' otycon aexp '#-}' {% runPV (unECP $4) >>= \ $4 ->
ams (sLL $1 $> (AnnD noExtField $ HsAnnotation noExtField
(getANN_PRAGs $1)
(TypeAnnProvenance $3) $4))
@@ -3562,6 +3562,12 @@ tyconsym :: { Located RdrName }
| '-' { sL1 $1 $! mkUnqual tcClsName (fsLit "-") }
| '.' { sL1 $1 $! mkUnqual tcClsName (fsLit ".") }
+-- An "ordinary" unqualified tycon. See `oqtycon` for the qualified version.
+-- These can appear in `ANN type` declarations (#19374).
+otycon :: { Located RdrName }
+ : tycon { $1 }
+ | '(' tyconsym ')' {% ams (sLL $1 $> (unLoc $2))
+ [mop $1,mj AnnVal $2,mcp $3] }
-----------------------------------------------------------------------------
-- Operators