Commit f663e507 authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari

Fix #15331 with careful blasts of parenthesizeHsType

Another `-ddump-splices` bug that can be solved with more
judicious use of parentheses.

Test Plan: make test TEST=T15331

Reviewers: goldfire, bgamari, alanz, tdammers

Reviewed By: tdammers

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15331

Differential Revision: https://phabricator.haskell.org/D4920

(cherry picked from commit b6a33861)
parent 113bdb8b
......@@ -818,7 +818,8 @@ cvtl e = wrapL (cvt e)
cvt (AppTypeE e t) = do { e' <- cvtl e
; t' <- cvtType t
; tp <- wrap_apps t'
; return $ HsAppType (mkHsWildCardBndrs tp) e' }
; let tp' = parenthesizeHsType appPrec tp
; return $ HsAppType (mkHsWildCardBndrs tp') e' }
cvt (LamE [] e) = cvt e -- Degenerate case. We convert the body as its
-- own expression to avoid pretty-printing
-- oddities that can result from zero-argument
......
......@@ -1425,8 +1425,8 @@ ppr_tylit (HsStrTy _ s) = text (show s)
hsTypeNeedsParens :: PprPrec -> HsType pass -> Bool
hsTypeNeedsParens p = go
where
go (HsForAllTy{}) = False
go (HsQualTy{}) = False
go (HsForAllTy{}) = p >= funPrec
go (HsQualTy{}) = p >= funPrec
go (HsBangTy{}) = p > topPrec
go (HsRecTy{}) = False
go (HsTyVar{}) = False
......
......@@ -178,7 +178,10 @@ mkHsApp e1 e2 = addCLoc e1 e2 (HsApp noExt e1 e2)
mkHsAppType :: (XAppTypeE (GhcPass id) ~ LHsWcType GhcRn)
=> LHsExpr (GhcPass id) -> LHsWcType GhcRn -> LHsExpr (GhcPass id)
mkHsAppType e t = addCLoc e (hswc_body t) (HsAppType t e)
mkHsAppType e t = addCLoc e t_body (HsAppType paren_wct e)
where
t_body = hswc_body t
paren_wct = t { hswc_body = parenthesizeHsType appPrec t_body }
mkHsAppTypes :: LHsExpr GhcRn -> [LHsWcType GhcRn] -> LHsExpr GhcRn
mkHsAppTypes = foldl mkHsAppType
......
......@@ -1706,7 +1706,7 @@ gen_Newtype_binds loc cls inst_tvs inst_tys rhs_ty
nlHsAppType :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlHsAppType e s = noLoc (HsAppType hs_ty e)
where
hs_ty = mkHsWildCardBndrs $ nlHsParTy (typeToLHsType s)
hs_ty = mkHsWildCardBndrs $ parenthesizeHsType appPrec (typeToLHsType s)
nlExprWithTySig :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlExprWithTySig e s = noLoc $ ExprWithTySig hs_ty
......
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module T15331 where
import Data.Proxy
$([d| f :: Proxy (Int -> Int)
f = Proxy @(Int -> Int)
|])
T15331.hs:(7,3)-(9,6): Splicing declarations
[d| f :: Proxy (Int -> Int)
f = Proxy @(Int -> Int) |]
======>
f :: Proxy (Int -> Int)
f = Proxy @(Int -> Int)
......@@ -415,3 +415,4 @@ test('T14885a', normal, compile, [''])
test('T14885b', normal, compile, [''])
test('T14885c', normal, compile, [''])
test('T15243', normal, compile, ['-dsuppress-uniques'])
test('T15331', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment