diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-10-04 18:13:28 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-10-04 18:13:29 -0400 |
commit | 251e3424a96986fca5164a2397783a1c066558fc (patch) | |
tree | 071158649a5071ff1ddadd0d7aa0b84b3cff9dac /compiler/parser | |
parent | ba163c3b3502df039e589c5bb0bc9ea767267b2a (diff) | |
download | haskell-251e3424a96986fca5164a2397783a1c066558fc.tar.gz |
Set `infixr -1 ->`
Summary:
This simply makes explicit what is already the case. Due to special
treatment in the parser, `->` has the lowest fixity. This patch propagates
that information to:
* GHCi, where `:info ->` now return the right fixity
* TH, where `reifyFixity` returns the right fixity
* the generated sources for `GHC.Prim`
See #15235.
Test Plan: make test
Reviewers: bgamari, alanz, RyanGlScott
Reviewed By: RyanGlScott
Subscribers: int-index, RyanGlScott, rwbarton, mpickering, carter
GHC Trac Issues: #15235
Differential Revision: https://phabricator.haskell.org/D5199
Diffstat (limited to 'compiler/parser')
-rw-r--r-- | compiler/parser/Parser.y | 6 | ||||
-rw-r--r-- | compiler/parser/RdrHsSyn.hs | 20 |
2 files changed, 18 insertions, 8 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index 25eb008895..74db997bbb 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -998,7 +998,7 @@ impspec :: { Located (Bool, Located [LIE GhcPs]) } prec :: { Located (SourceText,Int) } : {- empty -} { noLoc (NoSourceText,9) } | INTEGER - {% checkPrecP (sL1 $1 (getINTEGERs $1,fromInteger (il_value (getINTEGER $1)))) } + { sL1 $1 (getINTEGERs $1,fromInteger (il_value (getINTEGER $1))) } infix :: { Located FixityDirection } : 'infix' { sL1 $1 InfixN } @@ -2378,7 +2378,8 @@ sigdecl :: { LHsDecl GhcPs } [mu AnnDcolon $4] } } | infix prec ops - {% ams (sLL $1 $> $ SigD noExt + {% checkPrecP $2 $3 >> + ams (sLL $1 $> $ SigD noExt (FixSig noExt (FixitySig noExt (fromOL $ unLoc $3) (Fixity (fst $ unLoc $2) (snd $ unLoc $2) (unLoc $1))))) [mj AnnInfix $1,mj AnnVal $2] } @@ -3243,6 +3244,7 @@ op :: { Located RdrName } -- used in infix decls : varop { $1 } | conop { $1 } | '->' { sL1 $1 $ getRdrName funTyCon } + | '~' { sL1 $1 $ eqTyCon_RDR } varop :: { Located RdrName } : varsym { $1 } diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs index 91fcb0d3fd..1015319986 100644 --- a/compiler/parser/RdrHsSyn.hs +++ b/compiler/parser/RdrHsSyn.hs @@ -87,7 +87,7 @@ import BasicTypes import TcEvidence ( idHsWrapper ) import Lexer import Lexeme ( isLexCon ) -import Type ( TyThing(..) ) +import Type ( TyThing(..), funTyCon ) import TysWiredIn ( cTupleTyConName, tupleTyCon, tupleDataCon, nilDataConName, nilDataConKey, listTyConName, listTyConKey, eqTyCon_RDR, @@ -1756,11 +1756,19 @@ cmdStmtFail loc e = parseErrorSDoc loc --------------------------------------------------------------------------- -- Miscellaneous utilities -checkPrecP :: Located (SourceText,Int) -> P (Located (SourceText,Int)) -checkPrecP (L l (src,i)) - | 0 <= i && i <= maxPrecedence = return (L l (src,i)) - | otherwise - = parseErrorSDoc l (text ("Precedence out of range: " ++ show i)) +-- | Check if a fixity is valid. We support bypassing the usual bound checks +-- for some special operators. +checkPrecP + :: Located (SourceText,Int) -- ^ precedence + -> Located (OrdList (Located RdrName)) -- ^ operators + -> P () +checkPrecP (L l (_,i)) (L _ ol) + | 0 <= i, i <= maxPrecedence = pure () + | all specialOp ol = pure () + | otherwise = parseErrorSDoc l (text ("Precedence out of range: " ++ show i)) + where + specialOp op = unLoc op `elem` [ eqTyCon_RDR + , getRdrName funTyCon ] mkRecConstrOrUpdate :: LHsExpr GhcPs |