diff options
author | nineonine <mail4chemik@gmail.com> | 2019-07-02 12:44:22 -0700 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-07-05 07:08:17 -0400 |
commit | 2fd1ed541ae55a30ef65e18dc09bba993f37c70e (patch) | |
tree | f78a6c1b556efba03dbace8671bd1e12e34492b5 /libraries | |
parent | 62b82135a50b15869c425ef5e7dc35700e846228 (diff) | |
download | haskell-2fd1ed541ae55a30ef65e18dc09bba993f37c70e.tar.gz |
Fix #16895 by checking whether infix expression operator is a variable
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 5 | ||||
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 14 |
2 files changed, 13 insertions, 6 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs index 6eaadd648e..792a78b606 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs @@ -123,7 +123,10 @@ isSymOcc n pprInfixExp :: Exp -> Doc pprInfixExp (VarE v) = pprName' Infix v pprInfixExp (ConE v) = pprName' Infix v -pprInfixExp _ = text "<<Non-variable/constructor in infix context>>" +pprInfixExp (UnboundVarE v) = pprName' Infix v +-- This case will only ever be reached in exceptional circumstances. +-- For example, when printing an error message in case of a malformed expression. +pprInfixExp e = text "`" <> ppr e <> text "`" pprExp :: Precedence -> Exp -> Doc pprExp _ (VarE v) = pprName' Applied v diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index 2d79d5a28f..f79a8e2b0c 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -1895,11 +1895,15 @@ data Exp | InfixE (Maybe Exp) Exp (Maybe Exp) -- ^ @{x + y} or {(x+)} or {(+ x)} or {(+)}@ - -- It's a bit gruesome to use an Exp as the - -- operator, but how else can we distinguish - -- constructors from non-constructors? - -- Maybe there should be a var-or-con type? - -- Or maybe we should leave it to the String itself? + -- It's a bit gruesome to use an Exp as the operator when a Name + -- would suffice. Historically, Exp was used to make it easier to + -- distinguish between infix constructors and non-constructors. + -- This is a bit overkill, since one could just as well call + -- `startsConId` or `startsConSym` (from `GHC.Lexeme`) on a Name. + -- Unfortunately, changing this design now would involve lots of + -- code churn for consumers of the TH API, so we continue to use + -- an Exp as the operator and perform an extra check during conversion + -- to ensure that the Exp is a constructor or a variable (#16895). | UInfixE Exp Exp Exp -- ^ @{x + y}@ -- |