sigP. Needs tests and thinking about parens. (#35)

This commit is contained in:
Judah Jacobson 2019-08-25 09:13:59 -07:00 committed by GitHub
parent a792e98f49
commit 3db45a3f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,7 @@ module GHC.SourceGen.Pat
, recordConP
, strictP
, lazyP
, sigP
) where
import SrcLoc (unLoc)
@ -24,6 +25,7 @@ import GHC.SourceGen.Name.Internal
import GHC.SourceGen.Overloaded (par)
import GHC.SourceGen.Expr.Internal (litNeedsParen, overLitNeedsParen)
import GHC.SourceGen.Syntax.Internal
import GHC.SourceGen.Type.Internal (sigWcType)
-- | A wild pattern (@_@).
wildP :: Pat'
@ -101,3 +103,17 @@ strictP = noExt BangPat . builtPat . parenthesize
-- > lazyP (conP "A" [var x])
lazyP :: Pat' -> Pat'
lazyP = noExt LazyPat . builtPat . parenthesize
-- | A pattern type signature
--
-- > x :: y
-- > =====
-- > sigPat (var "x") (var "y")
sigP :: Pat' -> HsType' -> Pat'
#if MIN_VERSION_ghc(8,8,0)
sigP p t = noExt SigPat p (sigWcType t)
#elif MIN_VERSION_ghc(8,6,0)
sigP p t = SigPat (sigWcType t) (builtPat p)
#else
sigP p t = SigPatIn (builtPat p) (sigWcType t)
#endif

View File

@ -270,6 +270,10 @@ patsTest dflags = testGroup "Pats"
, "~(B y)" :~ lazyP $ conP "B" [var "y"]
, "~_" :~ lazyP wildP
]
, test "sigPat"
[ "x :: A" :~ sigP (var "x") (var "A")
, "A x :: A x" :~ sigP (conP "A" [var "x"]) (var "A" @@ var "x")
]
]
where
test = testPats dflags