Skip to content

Commit ba7b2d0

Browse files
updates for GHC HEAD
1 parent 514ad8f commit ba7b2d0

File tree

15 files changed

+110
-94
lines changed

15 files changed

+110
-94
lines changed

hlint.cabal

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ library
8181
deriving-aeson >= 0.2,
8282
filepattern >= 0.1.1
8383

84-
if !flag(ghc-lib) && impl(ghc >= 9.12.1) && impl(ghc < 9.13.0)
84+
if !flag(ghc-lib) && impl(ghc >= 9.14.1) && impl(ghc < 9.15.0)
8585
build-depends:
86-
ghc == 9.12.*,
86+
ghc == 9.14.*,
8787
ghc-boot-th,
8888
ghc-boot
8989
else
9090
build-depends:
91-
ghc-lib-parser == 9.12.*
91+
ghc-lib-parser == 9.14.*
9292
build-depends:
93-
ghc-lib-parser-ex >= 9.12 && < 9.13
93+
ghc-lib-parser-ex >= 9.14 && < 9.15
9494

9595
if flag(gpl)
9696
build-depends: hscolour >= 1.21
@@ -185,3 +185,5 @@ executable hlint
185185
ghc-options: -rtsopts -with-rtsopts=-A32m
186186
if flag(threaded)
187187
ghc-options: -threaded
188+
if os(darwin)
189+
ld-options: -framework Security

src/Config/Compute.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import GHC.Util
99
import Config.Type
1010
import Fixity
1111
import Data.Generics.Uniplate.DataOnly
12+
import Data.List.NonEmpty(NonEmpty(..))
1213
import GHC.Hs hiding (Warning)
1314
import GHC.Types.Name.Reader
1415
import GHC.Types.Name
@@ -56,7 +57,7 @@ findBind FunBind{fun_id, fun_matches} = findExp (unLoc fun_id) [] $ HsLam noAnn
5657
findBind _ = []
5758

5859
findExp :: IdP GhcPs -> [String] -> HsExpr GhcPs -> [Setting]
59-
findExp name vs (HsLam _ LamSingle MG{mg_alts=L _ [L _ Match{m_pats=L _ pats, m_grhss=GRHSs{grhssGRHSs=[L _ (GRHS _ [] x)], grhssLocalBinds=(EmptyLocalBinds _)}}]})
60+
findExp name vs (HsLam _ LamSingle MG{mg_alts=L _ [L _ Match{m_pats=L _ pats, m_grhss=GRHSs{grhssGRHSs=(L _ (GRHS _ [] x) :| []), grhssLocalBinds=(EmptyLocalBinds _)}}]})
6061
= if length pats == length ps then findExp name (vs++ps) $ unLoc x else []
6162
where ps = [rdrNameStr x | L _ (VarPat _ x) <- pats]
6263
findExp name vs HsLam{} = []

src/GHC/Util/Brackets.hs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ instance Brackets (LocatedA (HsExpr GhcPs)) where
3535

3636
isAtom (L _ x) = case x of
3737
HsVar{} -> True
38-
HsUnboundVar{} -> True
38+
HsHole{} -> True
3939
-- Only relevant for OverloadedRecordDot extension
4040
HsGetField{} -> True
4141
HsOverLabel{} -> True
@@ -59,12 +59,10 @@ instance Brackets (LocatedA (HsExpr GhcPs)) where
5959
_ -> False
6060
where
6161
isNegativeLit (HsInt _ i) = il_neg i
62-
isNegativeLit (HsRat _ f _) = fl_neg f
6362
isNegativeLit (HsFloatPrim _ f) = fl_neg f
6463
isNegativeLit (HsDoublePrim _ f) = fl_neg f
6564
isNegativeLit (HsIntPrim _ x) = x < 0
6665
isNegativeLit (HsInt64Prim _ x) = x < 0
67-
isNegativeLit (HsInteger _ x _) = x < 0
6866
isNegativeLit _ = False
6967
isNegativeOverLit OverLit {ol_val=HsIntegral i} = il_neg i
7068
isNegativeOverLit OverLit {ol_val=HsFractional f} = fl_neg f
@@ -119,7 +117,7 @@ instance Brackets (LocatedA (Pat GhcPs)) where
119117
ConPat _ _ RecCon{} -> False
120118
-- Before we only checked args, but not type args, resulting in a
121119
-- false positive for things like (Proxy @a)
122-
ConPat _ _ (PrefixCon [] []) -> True
120+
ConPat _ _ (PrefixCon []) -> True
123121
VarPat{} -> True
124122
WildPat{} -> True
125123
SumPat{} -> True
@@ -131,8 +129,6 @@ instance Brackets (LocatedA (Pat GhcPs)) where
131129
isSignedLit HsInt{} = True
132130
isSignedLit HsIntPrim{} = True
133131
isSignedLit HsInt64Prim{} = True
134-
isSignedLit HsInteger{} = True
135-
isSignedLit HsRat{} = True
136132
isSignedLit HsFloatPrim{} = True
137133
isSignedLit HsDoublePrim{} = True
138134
isSignedLit _ = False

src/GHC/Util/FreeVars.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Data.Generics.Uniplate.DataOnly
1818
import Data.Monoid
1919
import Data.Semigroup
2020
import Data.List.Extra
21+
import Data.List.NonEmpty(toList)
2122
import Data.Set (Set)
2223
import Data.Set qualified as Set
2324
import Prelude
@@ -97,7 +98,7 @@ unqualNames _ = []
9798

9899
instance FreeVars (LocatedA (HsExpr GhcPs)) where
99100
freeVars (L _ (HsVar _ x)) = Set.fromList $ unqualNames x -- Variable.
100-
freeVars (L _ (HsUnboundVar _ x)) = Set.fromList [rdrNameOcc x] -- Unbound variable; also used for "holes".
101+
freeVars (L _ (HsHole (HoleVar (L _ x)))) = Set.fromList [rdrNameOcc x] -- Unbound variable; also used for "holes".
101102
freeVars (L _ (HsLam _ LamSingle mg)) = free (allVars mg) -- Lambda abstraction. Currently always a single match.
102103
freeVars (L _ (HsLam _ _ MG{mg_alts=(L _ ms)})) = free (allVars ms) -- Lambda case
103104
freeVars (L _ (HsCase _ of_ MG{mg_alts=(L _ ms)})) = freeVars of_ ^+ free (allVars ms) -- Case expr.
@@ -123,7 +124,7 @@ instance FreeVars (LocatedA (HsExpr GhcPs)) where
123124
case flds of
124125
RegularRecUpdFields _ fs -> Set.unions $ freeVars e : map freeVars fs
125126
OverloadedRecUpdFields _ ps -> Set.unions $ freeVars e : map freeVars ps
126-
freeVars (L _ (HsMultiIf _ grhss)) = free (allVars grhss) -- Multi-way if.
127+
freeVars (L _ (HsMultiIf _ grhss)) = free (allVars (toList grhss)) -- Multi-way if.
127128
freeVars (L _ (HsTypedBracket _ e)) = freeVars e
128129
freeVars (L _ (HsUntypedBracket _ (ExpBr _ e))) = freeVars e
129130
freeVars (L _ (HsUntypedBracket _ (VarBr _ _ v))) = Set.fromList [occName (unLoc v)]
@@ -240,7 +241,7 @@ instance AllVars (HsStmtContext (GenLocated SrcSpanAnnN RdrName)) where
240241
allVars _ = mempty
241242

242243
instance AllVars (GRHSs GhcPs (LocatedA (HsExpr GhcPs))) where
243-
allVars (GRHSs _ grhss binds) = inVars binds (mconcatMap allVars grhss)
244+
allVars (GRHSs _ grhss binds) = inVars binds (mconcatMap allVars (toList grhss))
244245

245246
instance AllVars (LocatedAn NoEpAnns (GRHS GhcPs (LocatedA (HsExpr GhcPs)))) where
246247
allVars (L _ (GRHS _ guards expr)) = Vars (bound gs) (free gs ^+ (freeVars expr ^- bound gs)) where gs = allVars guards

src/GHC/Util/HsExpr.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Control.Monad.Trans.Writer.CPS
3333
import Data.Data
3434
import Data.Generics.Uniplate.DataOnly
3535
import Data.List.Extra
36+
import Data.List.NonEmpty(NonEmpty(..), fromList, toList)
3637
import Data.Tuple.Extra
3738
import Data.Maybe
3839

@@ -57,7 +58,7 @@ dotApps (x : xs) = dotApp x (dotApps xs)
5758

5859
-- | @lambda [p0, p1..pn] body@ makes @\p1 p1 .. pn -> body@
5960
lambda :: [LPat GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
60-
lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc) (noLocA [noLocA $ Match noExtField (LamAlt LamSingle) (L noSpanAnchor vs) (GRHSs emptyComments [noLocA $ GRHS noAnn [] body] (EmptyLocalBinds noExtField))]))
61+
lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc) (noLocA [noLocA $ Match noExtField (LamAlt LamSingle) (L noSpanAnchor vs) (GRHSs emptyComments (noLocA (GRHS noAnn [] body) :| []) (EmptyLocalBinds noExtField))]))
6162

6263
-- | 'paren e' wraps 'e' in parens if 'e' is non-atomic.
6364
paren :: LHsExpr GhcPs -> LHsExpr GhcPs
@@ -124,7 +125,7 @@ simplifyExp (L l (OpApp _ x op y)) | isDol op = L l (HsApp noExtField x (nlHsPar
124125
simplifyExp e@(L _ (HsLet _ ((HsValBinds _ (ValBinds _ binds []))) z)) =
125126
-- An expression of the form, 'let x = y in z'.
126127
case binds of
127-
[L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _ _) (L _ []) (GRHSs _ [L _ (GRHS _ [] y)] ((EmptyLocalBinds _))))])))]
128+
[L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _ _) (L _ []) (GRHSs _ (L _ (GRHS _ [] y) :| []) ((EmptyLocalBinds _))))])))]
128129
-- If 'x' is not in the free variables of 'y', beta-reduce to
129130
-- 'z[(y)/x]'.
130131
| occNameStr x `notElem` vars y && length [() | Unqual a <- universeBi z, a == rdrNameOcc x] <= 1 ->
@@ -251,12 +252,11 @@ niceLambdaR parent = go
251252
-- Base case. Just a good old fashioned lambda.
252253
go ss e =
253254
let grhs = noLocA $ GRHS noAnn [] e :: LGRHS GhcPs (LHsExpr GhcPs)
254-
grhss = GRHSs {grhssExt = emptyComments, grhssGRHSs=[grhs], grhssLocalBinds=EmptyLocalBinds noExtField}
255+
grhss = GRHSs {grhssExt = emptyComments, grhssGRHSs=fromList [grhs], grhssLocalBinds=EmptyLocalBinds noExtField}
255256
match = noLocA $ Match {m_ext=noExtField, m_ctxt=LamAlt LamSingle, m_pats=noLocA $ map strToPat ss, m_grhss=grhss} :: LMatch GhcPs (LHsExpr GhcPs)
256257
matchGroup = MG {mg_ext=Generated OtherExpansion SkipPmc, mg_alts=noLocA [match]}
257258
in (noLocA $ HsLam noAnn LamSingle matchGroup, const [])
258259

259-
260260
-- 'case' and 'if' expressions have branches, nothing else does (this
261261
-- doesn't consider 'HsMultiIf' perhaps it should?).
262262
replaceBranches :: LHsExpr GhcPs -> ([LHsExpr GhcPs], [LHsExpr GhcPs] -> LHsExpr GhcPs)
@@ -266,12 +266,12 @@ replaceBranches (L s (HsCase _ a (MG FromSource (L l bs)))) =
266266
(concatMap f bs, L s . HsCase noAnn a . MG (Generated OtherExpansion SkipPmc). L l . g bs)
267267
where
268268
f :: LMatch GhcPs (LHsExpr GhcPs) -> [LHsExpr GhcPs]
269-
f (L _ (Match _ CaseAlt _ (GRHSs _ xs _))) = [x | (L _ (GRHS _ _ x)) <- xs]
269+
f (L _ (Match _ CaseAlt _ (GRHSs _ xs _))) = [x | (L _ (GRHS _ _ x)) <- toList xs]
270270
f _ = error "GHC.Util.HsExpr.replaceBranches: unexpected XMatch"
271271

272272
g :: [LMatch GhcPs (LHsExpr GhcPs)] -> [LHsExpr GhcPs] -> [LMatch GhcPs (LHsExpr GhcPs)]
273273
g (L s1 (Match _ CaseAlt a (GRHSs _ ns b)) : rest) xs =
274-
L s1 (Match noExtField CaseAlt a (GRHSs emptyComments [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip ns as] b)) : g rest bs
274+
L s1 (Match noExtField CaseAlt a (GRHSs emptyComments (fromList [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip (toList ns) as]) b)) : g rest bs
275275
where (as, bs) = splitAt (length ns) xs
276276
g [] [] = []
277277
g _ _ = error "GHC.Util.HsExpr.replaceBranches': internal invariant failed, lists are of differing lengths"

src/GHC/Util/Unify.hs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ unify' nm root x y
120120
| Just (x :: EpAnn AnnExplicitSum) <- cast x = Just mempty
121121
| Just (x :: EpAnn AnnFieldLabel) <- cast x = Just mempty
122122
| Just (x :: EpAnn (AnnList [EpToken ","])) <- cast x = Just mempty
123+
| Just (x :: EpAnn (AnnList ())) <- cast x = Just mempty
124+
| Just (x :: EpAnn (AnnList (EpToken "where"))) <- cast x = Just mempty
125+
| Just (x :: EpAnn (AnnList (EpToken "hiding", [EpToken ","]))) <- cast x = Just mempty
123126
| Just (x :: EpAnn AnnListItem) <- cast x = Just mempty
124127
| Just (x :: EpAnn AnnParen) <- cast x = Just mempty
125128
| Just (x :: EpAnn AnnPragma) <- cast x = Just mempty
@@ -130,22 +133,38 @@ unify' nm root x y
130133
| Just (x :: EpAnn EpAnnHsCase) <- cast x = Just mempty
131134
| Just (x :: EpAnn EpAnnImportDecl) <- cast x = Just mempty
132135
| Just (x :: EpAnn EpAnnSumPat) <- cast x = Just mempty
133-
| Just (x :: EpAnn EpAnnUnboundVar) <- cast x = Just mempty
134136
| Just (x :: EpAnn GrhsAnn) <- cast x = Just mempty
135137
| Just (x :: EpAnn HsRuleAnn) <- cast x = Just mempty
136138
| Just (x :: EpAnn NameAnn) <- cast x = Just mempty
137139
| Just (x :: EpAnn NoEpAnns) <- cast x = Just mempty
138-
| Just (x :: EpToken "let") <- cast x = Just mempty
139-
| Just (x :: EpToken "in") <- cast x = Just mempty
140-
| Just (x :: EpToken "@") <- cast x = Just mempty
140+
| Just (x :: EpToken "|") <- cast x = Just mempty
141+
| Just (x :: EpToken ",") <- cast x = Just mempty
142+
| Just (x :: EpToken ";") <- cast x = Just mempty
143+
| Just (x :: EpToken "`") <- cast x = Just mempty
144+
| Just (x :: EpToken ".") <- cast x = Just mempty
145+
| Just (x :: EpToken "\\") <- cast x = Just mempty
141146
| Just (x :: EpToken "(") <- cast x = Just mempty
142147
| Just (x :: EpToken ")") <- cast x = Just mempty
148+
| Just (x :: EpToken "@") <- cast x = Just mempty
149+
| Just (x :: EpToken "#-}") <- cast x = Just mempty
150+
| Just (x :: EpToken "if") <- cast x = Just mempty
151+
| Just (x :: EpToken "then") <- cast x = Just mempty
152+
| Just (x :: EpToken "let") <- cast x = Just mempty
153+
| Just (x :: EpToken "else") <- cast x = Just mempty
154+
| Just (x :: EpToken "case") <- cast x = Just mempty
155+
| Just (x :: EpToken "of") <- cast x = Just mempty
156+
| Just (x :: EpToken "in") <- cast x = Just mempty
143157
| Just (x :: EpToken "type") <- cast x = Just mempty
144158
| Just (x :: EpToken "%") <- cast x = Just mempty
145159
| Just (x :: EpToken "%1") <- cast x = Just mempty
146-
| Just (x :: EpToken "") <- cast x = Just mempty
160+
| Just (x :: EpToken "proc") <- cast x = Just mempty
161+
| Just (x :: EpToken "static") <- cast x = Just mempty
162+
| Just (x :: EpToken "qualified") <- cast x = Just mempty
163+
| Just (x :: EpToken "safe") <- cast x = Just mempty
164+
| Just (x :: EpToken "as") <- cast x = Just mempty
165+
| Just (x :: EpToken "import") <- cast x = Just mempty
147166
| Just (x :: EpUniToken "->" "") <- cast x = Just mempty
148-
| Just (x :: TokenLocation) <- cast y = Just mempty
167+
| Just (x :: EpUniToken "::" "") <- cast x = Just mempty
149168
| Just (y :: SrcSpan) <- cast y = Just mempty
150169

151170
| otherwise = unifyDef' nm x y

src/GHC/Util/View.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import GHC.Types.SrcLoc
1313
import GHC.Types.Basic
1414
import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader
1515
import GHC.Util.Brackets
16+
import Data.List.NonEmpty(NonEmpty(..))
1617

1718
fromParen :: LocatedA (HsExpr GhcPs) -> LocatedA (HsExpr GhcPs)
1819
fromParen x = maybe x fromParen $ remParen x
@@ -33,7 +34,7 @@ data LamConst1 = NoLamConst1 | LamConst1 (LocatedA (HsExpr GhcPs))
3334

3435
instance View (LocatedA (HsExpr GhcPs)) LamConst1 where
3536
view (fromParen -> (L _ (HsLam _ _ (MG FromSource (L _ [L _ (Match _ (LamAlt _) (L _ [L _ WildPat {}])
36-
(GRHSs _ [L _ (GRHS _ [] x)] ((EmptyLocalBinds _))))]))))) = LamConst1 x
37+
(GRHSs _ (L _ (GRHS _ [] x) :| []) ((EmptyLocalBinds _))))]))))) = LamConst1 x
3738
view _ = NoLamConst1
3839

3940
instance View (LocatedA (HsExpr GhcPs)) RdrName_ where
@@ -54,12 +55,12 @@ instance View (LocatedA (Pat GhcPs)) PVar_ where
5455
view _ = NoPVar_
5556

5657
instance View (LocatedA (Pat GhcPs)) PApp_ where
57-
view (fromPParen -> L _ (ConPat _ (L _ x) (PrefixCon _ args))) =
58+
view (fromPParen -> L _ (ConPat _ (L _ x) (PrefixCon args))) =
5859
PApp_ (occNameStr x) args
5960
view (fromPParen -> L _ (ConPat _ (L _ x) (InfixCon lhs rhs))) =
6061
PApp_ (occNameStr x) [lhs, rhs]
6162
view _ = NoPApp_
6263

6364
-- A lambda with no guards and no where clauses
6465
pattern SimpleLambda :: [LocatedA (Pat GhcPs)] -> LocatedA (HsExpr GhcPs) -> LocatedA (HsExpr GhcPs)
65-
pattern SimpleLambda vs body <- L _ (HsLam _ LamSingle (MG _ (L _ [L _ (Match _ _ (L _ vs) (GRHSs _ [L _ (GRHS _ [] body)] ((EmptyLocalBinds _))))])))
66+
pattern SimpleLambda vs body <- L _ (HsLam _ LamSingle (MG _ (L _ [L _ (Match _ _ (L _ vs) (GRHSs _ (L _ (GRHS _ [] body) :| []) ((EmptyLocalBinds _))))])))

src/Hint/Bracket.hs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,14 @@ bracketError :: (Outputable a, Outputable b, Brackets (LocatedA b)) => String ->
245245
bracketError msg o x =
246246
warn msg (reLoc o) (reLoc x) [Replace (findType x) (toSSA o) [("x", toSSA x)] "x"]
247247

248-
fieldDecl :: LConDeclField GhcPs -> [Idea]
249-
fieldDecl o@(L loc f@ConDeclField{cd_fld_type=v@(L l (HsParTy _ c))}) =
250-
let r = L loc (f{cd_fld_type=c}) :: LConDeclField GhcPs in
248+
fieldDecl :: LHsConDeclRecField GhcPs -> [Idea]
249+
fieldDecl o@(L loc f@HsConDeclRecField{cdrf_spec = CDF{cdf_bang = NoSrcStrict, cdf_type = v@(L l (HsParTy _ c))}}) =
250+
let r = L loc (f{cdrf_spec = (cdrf_spec f){cdf_type = c}}) :: LHsConDeclRecField GhcPs in
251251
[rawIdea Suggestion "Redundant bracket" (locA l)
252-
(showSDocUnsafe $ ppr_fld o) -- Note this custom printer!
253-
(Just (showSDocUnsafe $ ppr_fld r))
252+
(showSDocUnsafe $ ppr o)
253+
(Just (showSDocUnsafe $ ppr r))
254254
[]
255255
[Replace Type (toSSA v) [("x", toSSA c)] "x"]]
256-
where
257-
-- If we call 'unsafePrettyPrint' on a field decl, we won't like
258-
-- the output (e.g. "[foo, bar] :: T"). Here we use a custom
259-
-- printer to work around (snarfed from Hs.Types.pprConDeclFields)
260-
ppr_fld (L _ ConDeclField { cd_fld_names = ns, cd_fld_type = ty, cd_fld_doc = doc })
261-
= pprMaybeWithDoc doc (ppr_names ns <+> dcolon <+> ppr ty)
262-
ppr_fld (L _ (XConDeclField x)) = ppr x
263-
264-
ppr_names [n] = ppr n
265-
ppr_names ns = sep (punctuate comma (map ppr ns))
266256
fieldDecl _ = []
267257

268258
-- This function relies heavily on fixities having been applied to the

src/Hint/Lambda.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ module Hint.Lambda(lambdaHint) where
117117

118118
import Hint.Type (DeclHint, Idea, Note(RequiresExtension), suggest, warn, toSS, toSSA, suggestN, ideaNote, substVars, toRefactSrcSpan)
119119
import Util
120+
import Data.List qualified
120121
import Data.List.Extra
122+
import Data.List.NonEmpty(NonEmpty(..))
121123
import Data.Set (Set)
122124
import Data.Set qualified as Set
123125
import Refact.Types hiding (Match)
@@ -156,7 +158,7 @@ lambdaBind :: LHsBind GhcPs -> RType -> [Idea]
156158
lambdaBind
157159
o@(L _ origBind@FunBind {fun_id = funName@(L loc1 _), fun_matches =
158160
MG {mg_alts =
159-
L _ [L _ (Match _ ctxt@(FunRhs _ Prefix _ _) (L _ pats) (GRHSs _ [L _ (GRHS _ [] origBody@(L loc2 _))] bind))]}}) rtype
161+
L _ [L _ (Match _ ctxt@(FunRhs _ Prefix _ _) (L _ pats) (GRHSs _ (L _ (GRHS _ [] origBody@(L loc2 _)) :| []) bind))]}}) rtype
160162
| EmptyLocalBinds _ <- bind
161163
, isLambda $ fromParen origBody
162164
, null (universeBi pats :: [HsExpr GhcPs])
@@ -179,7 +181,7 @@ lambdaBind
179181
where
180182
reform :: [LPat GhcPs] -> LHsExpr GhcPs -> Located (HsDecl GhcPs)
181183
reform ps b = L (combineSrcSpans (locA loc1) (locA loc2)) $ ValD noExtField $
182-
origBind {fun_matches = MG (Generated OtherExpansion SkipPmc) (noLocA [noLocA $ Match noExtField ctxt (L noSpanAnchor ps) $ GRHSs emptyComments [noLocA $ GRHS noAnn [] b] $ EmptyLocalBinds noExtField])}
184+
origBind {fun_matches = MG (Generated OtherExpansion SkipPmc) (noLocA [noLocA $ Match noExtField ctxt (L noSpanAnchor ps) $ GRHSs emptyComments (noLocA (GRHS noAnn [] b) :| []) $ EmptyLocalBinds noExtField])}
183185

184186
mkSubtsAndTpl newPats newBody = (sub, tpl)
185187
where
@@ -351,7 +353,7 @@ fromLambda x = ([], x)
351353
mkOrigPats :: Maybe String -> [LPat GhcPs] -> ([LPat GhcPs], [String])
352354
mkOrigPats funName pats = (zipWith munge vars pats', vars)
353355
where
354-
(Set.unions -> used, pats') = unzip (map f pats)
356+
(Set.unions -> used, pats') = Data.List.unzip (map f pats)
355357

356358
-- Remove variables that occur in the function name or patterns with wildcards
357359
vars = filter (\s -> s `Set.notMember` used && Just s /= funName) substVars

src/Hint/ListRec.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Hint.Type (DeclHint, Severity(Suggestion, Warning), idea, toSSA)
3535

3636
import Data.Generics.Uniplate.DataOnly
3737
import Data.List.Extra
38+
import Data.List.NonEmpty(NonEmpty(..))
3839
import Data.Maybe
3940
import Data.Either.Extra
4041
import Control.Monad
@@ -140,7 +141,7 @@ asDo (view ->
140141
L _ Match { m_ctxt=(LamAlt LamSingle)
141142
, m_pats=L _ [v@(L _ VarPat{})]
142143
, m_grhss=GRHSs _
143-
[L _ (GRHS _ [] rhs)]
144+
(L _ (GRHS _ [] rhs) :| [])
144145
(EmptyLocalBinds _)}]}))
145146
) =
146147
[ noLocA $ BindStmt noAnn v lhs
@@ -174,7 +175,7 @@ findCase x = do
174175
let ps12 = let (a, b) = splitAt p1 ps1 in map strToPat (a ++ xs : b) -- Function arguments.
175176
emptyLocalBinds = EmptyLocalBinds noExtField :: HsLocalBindsLR GhcPs GhcPs -- Empty where clause.
176177
gRHS e = noLocA $ GRHS noAnn [] e :: LGRHS GhcPs (LHsExpr GhcPs) -- Guarded rhs.
177-
gRHSSs e = GRHSs emptyComments [gRHS e] emptyLocalBinds -- Guarded rhs set.
178+
gRHSSs e = GRHSs emptyComments (gRHS e :| []) emptyLocalBinds -- Guarded rhs set.
178179
match e = Match{m_ext=noExtField,m_pats=noLocA ps12, m_grhss=gRHSSs e, ..} -- Match.
179180
matchGroup e = MG{mg_alts=noLocA [noLocA $ match e], mg_ext=Generated OtherExpansion SkipPmc, ..} -- Match group.
180181
funBind e = FunBind {fun_matches=matchGroup e, ..} :: HsBindLR GhcPs GhcPs -- Fun bind.
@@ -208,7 +209,7 @@ findBranch (L _ x) = do
208209
Match { m_ctxt = FunRhs {mc_fun=(L _ name)}
209210
, m_pats = ps
210211
, m_grhss =
211-
GRHSs {grhssGRHSs=[L l (GRHS _ [] body)]
212+
GRHSs {grhssGRHSs=(L l (GRHS _ [] body) :| [])
212213
, grhssLocalBinds=EmptyLocalBinds _
213214
}
214215
} <- pure x
@@ -227,6 +228,6 @@ readPat :: LPat GhcPs -> Maybe (Either String BList)
227228
readPat (view -> PVar_ x) = Just $ Left x
228229
readPat (L _ (ParPat _ (L _ (ConPat _ (L _ n) (InfixCon (view -> PVar_ x) (view -> PVar_ xs))))))
229230
| n == consDataCon_RDR = Just $ Right $ BCons x xs
230-
readPat (L _ (ConPat _ (L _ n) (PrefixCon [] [])))
231+
readPat (L _ (ConPat _ (L _ n) (PrefixCon [])))
231232
| n == nameRdrName nilDataConName = Just $ Right BNil
232233
readPat _ = Nothing

0 commit comments

Comments
 (0)