Fix listPromotedTy on lists of one or zero elements. (#55)

We need the explicit `'` to distinguish from regular lists.
For simplicity, just use it for all type-level lists of
any length.
This commit is contained in:
Judah Jacobson 2019-10-17 11:01:35 -07:00 committed by GitHub
parent 5986388e5b
commit cf6eb5e260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,8 @@
## Unreleased
- Add `occNameToStr` and `nameToStr` to convert from the GHC types.
- Make `listPromotedTy` emit the promoted form `'[..]`,
to distinguish from regular list types of zero or one elements.
## 0.2.0.1
- Bump upper-bound to allow `QuickCheck-2.13`.

View File

@ -40,7 +40,9 @@ listTy :: HsType' -> HsType'
listTy = noExt HsListTy . builtLoc
listPromotedTy :: [HsType'] -> HsType'
listPromotedTy = withPlaceHolder (noExt HsExplicitListTy notPromoted) . map builtLoc
-- Lists of two or more elements don't need the explicit tick (`'`).
-- But for consistency, just always add it.
listPromotedTy = withPlaceHolder (noExt HsExplicitListTy promoted) . map builtLoc
-- | A function type.
--

View File

@ -95,9 +95,9 @@ typesTest dflags = testGroup "Type"
[ "()" :~ unit ]
, test "list"
[ "[x]" :~ listTy (var "x")
, "[]" :~ listPromotedTy []
, "[x]" :~ listPromotedTy [var "x"]
, "[y, z]" :~ listPromotedTy [var "y", var "z"]
, "'[]" :~ listPromotedTy []
, "'[x]" :~ listPromotedTy [var "x"]
, "'[y, z]" :~ listPromotedTy [var "y", var "z"]
]
, test "tyPromotedVar"
-- For some reason, older GHC pretty-printed an extra space.