summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2020-10-28 23:09:48 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-11-03 17:41:10 -0500
commit616bec0dee67ae4841c4e60e9406cc9c63358223 (patch)
tree699bfab7a19b5a8409394ab5ddaab729e115d496 /compiler
parent14ce454f7294381225b4211dc191a167a386e380 (diff)
downloadhaskell-616bec0dee67ae4841c4e60e9406cc9c63358223.tar.gz
Restrict Linear arrow %1 to exactly literal 1 only
This disallows `a %001 -> b`, and makes sure the type literal is printed from its SourceText so it is clear why. Closes #18888
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Hs/Type.hs4
-rw-r--r--compiler/GHC/Parser/PostProcess.hs3
2 files changed, 4 insertions, 3 deletions
diff --git a/compiler/GHC/Hs/Type.hs b/compiler/GHC/Hs/Type.hs
index 1845f060ed..1ae23c779d 100644
--- a/compiler/GHC/Hs/Type.hs
+++ b/compiler/GHC/Hs/Type.hs
@@ -1982,8 +1982,8 @@ ppr_fun_ty mult ty1 ty2
--------------------------
ppr_tylit :: HsTyLit -> SDoc
-ppr_tylit (HsNumTy _ i) = integer i
-ppr_tylit (HsStrTy _ s) = text (show s)
+ppr_tylit (HsNumTy source i) = pprWithSourceText source (integer i)
+ppr_tylit (HsStrTy source s) = pprWithSourceText source (text (show s))
-- | @'hsTypeNeedsParens' p t@ returns 'True' if the type @t@ needs parentheses
diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs
index 84aa3e09bc..e95abd6597 100644
--- a/compiler/GHC/Parser/PostProcess.hs
+++ b/compiler/GHC/Parser/PostProcess.hs
@@ -2620,7 +2620,8 @@ mkLHsOpTy x op y =
in L loc (mkHsOpTy x op y)
mkMultTy :: IsUnicodeSyntax -> Located Token -> LHsType GhcPs -> (HsArrow GhcPs, AddAnn)
-mkMultTy u tok t@(L _ (HsTyLit _ (HsNumTy _ 1)))
+mkMultTy u tok t@(L _ (HsTyLit _ (HsNumTy (SourceText "1") 1)))
+ -- See #18888 for the use of (SourceText "1") above
= (HsLinearArrow u, AddAnn AnnPercentOne (combineLocs tok t))
mkMultTy u tok t = (HsExplicitMult u t, AddAnn AnnPercent (getLoc tok))