{-# LANGUAGE CPP #-}
module Seminal.Enumerator.Expressions (
    enumerateChangesInExpression
) where
import Seminal.Enumerator.Enumerator (Enumerator)
import Seminal.Compiler.API
import Seminal.Change
import Data.Functor ((<&>))
import Data.List.HT (splitEverywhere)
import Seminal.Enumerator.Literals (enumerateChangeInLiteral, enumerateRaiseInLiterals)
import Data.Maybe (mapMaybe)
import Seminal.Enumerator.LocalBindings (enumerateChangesInLocalBinds)
import {-# SOURCE #-} Seminal.Enumerator.Matches (enumerateChangesInMatch)
import Data.List (permutations)

-- | Enumerate possible changes for expressions,
-- starting with replacing them with undefined.
-- See [API doc](https://hackage.haskell.org/package/ghc-9.6.1/docs/Language-Haskell-Syntax-Expr.html#t:HsExpr)
enumerateChangesInExpression :: Enumerator (HsExpr GhcPs)
enumerateChangesInExpression :: Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
expr SrcSpan
loc = [Change (HsExpr GhcPs)
change]
    where
        change :: Change (HsExpr GhcPs)
change = ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change
            (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr)
            (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> [HsExpr GhcPs] -> [ChangeNode (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HsExpr GhcPs
undefinedExpression, HsExpr GhcPs
emptyListExpression])
            SrcSpan
loc
            (Change (HsExpr GhcPs)
changeToStringChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:Change (HsExpr GhcPs)
changeToListChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:Change (HsExpr GhcPs)
changeToTrueChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:Change (HsExpr GhcPs)
changeToUnitChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:[Change (HsExpr GhcPs)]
subchanges)
            String
"The type of the expression is incorrect."
            ChangeType
Wildcard
        changeToUnit :: Change (HsExpr GhcPs)
changeToUnit = ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
unitExpression] SrcSpan
loc []
            String
"The expected type of the expression is `()`." ChangeType
Terminal
        -- | Wrap the expression into a list
        changeToList :: Change (HsExpr GhcPs)
changeToList = ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed [LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall {ann}. GenLocated (SrcAnn ann) (HsExpr GhcPs)
lexpr]] SrcSpan
loc []
            String
"The expected type of the expression is a list. You may have forgotten to wrap the expression into a list" ChangeType
Wrapping
        -- | Try to call `show` on the Expression
        changeToString :: Change (HsExpr GhcPs)
changeToString = ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall {e} {ann}. e -> GenLocated (SrcAnn ann) e
locMe (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ String -> HsExpr GhcPs
buildFunctionName String
"show") LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall {ann}. GenLocated (SrcAnn ann) (HsExpr GhcPs)
lexpr] SrcSpan
loc []
            String
"The expected type of the expression is a String. You may have forgotten to call the `show` method on the expression" ChangeType
Wrapping
            Change (HsExpr GhcPs)
-> (HsExpr GhcPs -> HsExpr GhcPs) -> Change (HsExpr GhcPs)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (LHsExpr GhcPs -> HsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs
wrapExprInPar (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> HsExpr GhcPs
-> HsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall {e} {ann}. e -> GenLocated (SrcAnn ann) e
locMe)
        changeToTrue :: Change (HsExpr GhcPs)
changeToTrue = ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XVar GhcPs -> LIdP GhcPs -> HsExpr GhcPs
forall p. XVar p -> LIdP p -> HsExpr p
HsVar XVar GhcPs
NoExtField
NoExtField LIdP GhcPs
GenLocated SrcSpanAnnN RdrName
forall {ann}. GenLocated (SrcAnn ann) RdrName
ltrue] SrcSpan
loc [] String
msg ChangeType
Wildcard
            where
                msg :: String
msg = String
"This expression might need to evaluate to a boolean value. It is not the case here. Check the type of the value."
                ltrue :: GenLocated (SrcAnn ann) RdrName
ltrue = SrcAnn ann -> RdrName -> GenLocated (SrcAnn ann) RdrName
forall l e. l -> e -> GenLocated l e
L (SrcSpan -> SrcAnn ann
forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
noSrcSpan) (OccName -> RdrName
mkRdrUnqual (String -> OccName
mkDataOcc String
"True"))
        -- | The other, specalised, changes to consider
        subchanges :: [Change (HsExpr GhcPs)]
subchanges = Enumerator (HsExpr GhcPs)
enumerateChangesInExpression' HsExpr GhcPs
expr SrcSpan
loc
        -- | Located expr
        lexpr :: GenLocated (SrcAnn ann) (HsExpr GhcPs)
lexpr = HsExpr GhcPs -> GenLocated (SrcAnn ann) (HsExpr GhcPs)
forall {e} {ann}. e -> GenLocated (SrcAnn ann) e
locMe HsExpr GhcPs
expr
        -- | Wrap HsExpr into LHsExpr
        locMe :: e -> GenLocated (SrcAnn ann) e
locMe = SrcAnn ann -> e -> GenLocated (SrcAnn ann) e
forall l e. l -> e -> GenLocated l e
L SrcAnn ann
forall ann. SrcAnn ann
noSrcSpanA

enumerateChangesInExpression' :: Enumerator (HsExpr GhcPs)
#if MIN_VERSION_ghc(9,4,1)
enumerateChangesInExpression' :: Enumerator (HsExpr GhcPs)
enumerateChangesInExpression' (HsPar XPar GhcPs
_ LHsToken "(" GhcPs
_ (L SrcAnn AnnListItem
lexpr HsExpr GhcPs
expr) LHsToken ")" GhcPs
_) SrcSpan
_ = 
#else
enumerateChangesInExpression' (HsPar _ (L lexpr expr)) _ =
#endif
    Enumerator (HsExpr GhcPs)
enumerateChangesInExpression' HsExpr GhcPs
expr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lexpr)
enumerateChangesInExpression' HsExpr GhcPs
expr SrcSpan
loc = case HsExpr GhcPs
expr of
    (ExplicitList XExplicitList GhcPs
ext [LHsExpr GhcPs]
elems) -> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a]
reverse -- Reverse because we started here w/ most specific
        (if [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsExpr GhcPs]
[GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
elems Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
            -- Extract Singleton into item
            then let L SrcAnn AnnListItem
_ HsExpr GhcPs
single = [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a. HasCallStack => [a] -> a
head [LHsExpr GhcPs]
[GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
elems in (
                ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
single] SrcSpan
loc []
                String
"The expected type of the expression is not a list of the given expression. You may need to remove brackets around it." ChangeType
Terminal Change (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:
                -- We rewrite the source, because it is the list, not the element inside it
                (Enumerator (HsExpr GhcPs)
enumerateChangesInExpression' HsExpr GhcPs
single SrcSpan
loc [Change (HsExpr GhcPs)]
-> (Change (HsExpr GhcPs) -> Change (HsExpr GhcPs))
-> [Change (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\Change (HsExpr GhcPs)
c -> Change (HsExpr GhcPs)
c { src :: ChangeNode (HsExpr GhcPs)
src = HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr }))
            )
            else []) [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++
        -- Turn a list into a tuple
        (ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitTuple GhcPs -> [HsTupArg GhcPs] -> Boxity -> HsExpr GhcPs
forall p. XExplicitTuple p -> [HsTupArg p] -> Boxity -> HsExpr p
ExplicitTuple XExplicitTuple GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed (XPresent GhcPs -> LHsExpr GhcPs -> HsTupArg GhcPs
forall id. XPresent id -> LHsExpr id -> HsTupArg id
Present XPresent GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsTupArg GhcPs)
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [HsTupArg GhcPs]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsExpr GhcPs]
[GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
elems) Boxity
Boxed] SrcSpan
loc []
            String
"The expected type of the expression is a tuple, not a list." ChangeType
TerminalChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:
        -- Remove element in list
        ([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)],
     GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs),
     [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [LHsExpr GhcPs]
[GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
elems
            [([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)],
  GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs),
  [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)])]
-> (([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)],
     GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs),
     [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)])
    -> Change (HsExpr GhcPs))
-> [Change (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
h, L SrcAnn AnnListItem
lremoved HsExpr GhcPs
removed, [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
t) -> ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change
                (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr)
                [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
ext ([LHsExpr GhcPs] -> HsExpr GhcPs)
-> [LHsExpr GhcPs] -> HsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
h [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
t] -- Removing element in list
                SrcSpan
loc
                (Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
removed (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lremoved)
                    [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lremoved)
                    [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
    -> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)])
-> [Change [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
i -> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
h [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
i] [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
t)
                    [Change [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]]
-> ([GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
    -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
ext))
                String
"The removed element is either of the wrong type, or its sub-expression does not type-check."
                ChangeType
Removal
            )
        ))
    (ExplicitTuple XExplicitTuple GhcPs
_ [Present XPresent GhcPs
_ (L SrcAnn AnnListItem
lunit HsExpr GhcPs
unit)] Boxity
_) -> [
        -- Turn a unit into an item
        -- Note: How to build a 1-tuple ?
        ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
unit] (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lunit) []
            String
"The expected type of the expression is a list, not a tuple." ChangeType
Terminal
        ]
    (ExplicitTuple XExplicitTuple GhcPs
xtuple [HsTupArg GhcPs]
args Boxity
box) -> if (HsTupArg GhcPs -> Bool) -> [HsTupArg GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all HsTupArg GhcPs -> Bool
forall {id}. HsTupArg id -> Bool
tupleArgIsPresent [HsTupArg GhcPs]
args
            then [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a]
reverse ([Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)])
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a b. (a -> b) -> a -> b
$ -- Reverse because we started here w/ most specific
                -- Turn a tuple into a list
                ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs))
-> HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed ([LHsExpr GhcPs] -> HsExpr GhcPs)
-> [LHsExpr GhcPs] -> HsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ (HsTupArg GhcPs
 -> Maybe (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
-> [HsTupArg GhcPs]
-> [GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe HsTupArg GhcPs -> Maybe (LHsExpr GhcPs)
HsTupArg GhcPs
-> Maybe (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
forall {id}. HsTupArg id -> Maybe (XRec id (HsExpr id))
getTupleArg [HsTupArg GhcPs]
args] SrcSpan
loc []
                    String
"The expected type of the expression is a list, not a tuple." ChangeType
TerminalChange (HsExpr GhcPs)
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:
                -- Enumerate each change for each element in the tuple
                [[Change (HsExpr GhcPs)]] -> [Change (HsExpr GhcPs)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([HsTupArg GhcPs]
-> [([HsTupArg GhcPs], HsTupArg GhcPs, [HsTupArg GhcPs])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [HsTupArg GhcPs]
args [([HsTupArg GhcPs], HsTupArg GhcPs, [HsTupArg GhcPs])]
-> (([HsTupArg GhcPs], HsTupArg GhcPs, [HsTupArg GhcPs])
    -> [Change (HsExpr GhcPs)])
-> [[Change (HsExpr GhcPs)]]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([HsTupArg GhcPs]
h, HsTupArg GhcPs
arg, [HsTupArg GhcPs]
t) -> case HsTupArg GhcPs
arg of
                    Present XPresent GhcPs
ext (L SrcAnn AnnListItem
lunit HsExpr GhcPs
unit) -> (Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
unit (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lunit))
                        [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> HsExpr GhcPs) -> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\HsExpr GhcPs
i -> XExplicitTuple GhcPs -> [HsTupArg GhcPs] -> Boxity -> HsExpr GhcPs
forall p. XExplicitTuple p -> [HsTupArg p] -> Boxity -> HsExpr p
ExplicitTuple XExplicitTuple GhcPs
xtuple ([HsTupArg GhcPs]
h [HsTupArg GhcPs] -> [HsTupArg GhcPs] -> [HsTupArg GhcPs]
forall a. [a] -> [a] -> [a]
++ [XPresent GhcPs -> LHsExpr GhcPs -> HsTupArg GhcPs
forall id. XPresent id -> LHsExpr id -> HsTupArg id
Present XPresent GhcPs
ext (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lunit HsExpr GhcPs
i)] [HsTupArg GhcPs] -> [HsTupArg GhcPs] -> [HsTupArg GhcPs]
forall a. [a] -> [a] -> [a]
++ [HsTupArg GhcPs]
t) Boxity
box)
                    HsTupArg GhcPs
_ -> []
                ))
            else []
        where
            tupleArgIsPresent :: HsTupArg id -> Bool
tupleArgIsPresent (Present {}) = Bool
True
            tupleArgIsPresent HsTupArg id
_ = Bool
False
            getTupleArg :: HsTupArg id -> Maybe (XRec id (HsExpr id))
getTupleArg (Present XPresent id
_ XRec id (HsExpr id)
arg) = XRec id (HsExpr id) -> Maybe (XRec id (HsExpr id))
forall a. a -> Maybe a
Just XRec id (HsExpr id)
arg
            getTupleArg HsTupArg id
_ = Maybe (XRec id (HsExpr id))
forall a. Maybe a
Nothing
    -- Attempts tweaks with litterals
    (HsLit XLitE GhcPs
ext HsLit GhcPs
literal) -> Enumerator (HsLit GhcPs)
enumerateChangeInLiteral HsLit GhcPs
literal SrcSpan
loc
        [Change (HsLit GhcPs)]
-> (HsLit GhcPs -> HsExpr GhcPs) -> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XLitE GhcPs -> HsLit GhcPs -> HsExpr GhcPs
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcPs
ext) [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ Enumerator (HsExpr GhcPs)
enumerateRaiseInLiterals HsExpr GhcPs
expr SrcSpan
loc
    -- In function application: try changes on functions and parameters
    (HsApp XApp GhcPs
a LHsExpr GhcPs
func LHsExpr GhcPs
param) -> [Change (HsExpr GhcPs)]
paramInsert [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
paramRemovals [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumF [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumParam [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
paramSwap
        where
            -- | Enumeration on the function
            enumF :: [Change (HsExpr GhcPs)]
enumF = let (L SrcAnn AnnListItem
lf HsExpr GhcPs
f) = LHsExpr GhcPs
func in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
f (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lf)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> HsExpr GhcPs) -> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\HsExpr GhcPs
c -> XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
a (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lf HsExpr GhcPs
c) LHsExpr GhcPs
param)
            -- | Enumeration on the parameters
            enumParam :: [Change (HsExpr GhcPs)]
enumParam = let (L SrcAnn AnnListItem
lp HsExpr GhcPs
p) = LHsExpr GhcPs
param in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
p (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lp)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> HsExpr GhcPs) -> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
a LHsExpr GhcPs
func (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> HsExpr GhcPs
-> HsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lp)
            paramRemovals :: [Change (HsExpr GhcPs)]
paramRemovals = [HsExpr GhcPs] -> [([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [HsExpr GhcPs]
paramList
                [([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])]
-> (([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])
    -> Change (HsExpr GhcPs))
-> [Change (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([HsExpr GhcPs]
h, HsExpr GhcPs
_, [HsExpr GhcPs]
t) -> ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change
                    (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr)
                    [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node ([HsExpr GhcPs] -> HsExpr GhcPs
exprListToHsApp ([HsExpr GhcPs]
h [HsExpr GhcPs] -> [HsExpr GhcPs] -> [HsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++ [HsExpr GhcPs]
t))]
                    SrcSpan
loc
                    []
                    String
"The removed expression is superfluous. Please, remove it."
                    ChangeType
Terminal
                )
            -- Swap Parameter
            paramSwap :: [Change (HsExpr GhcPs)]
paramSwap = [HsExpr GhcPs] -> [[HsExpr GhcPs]]
forall a. [a] -> [[a]]
permutations [HsExpr GhcPs]
paramList
                [[HsExpr GhcPs]]
-> ([HsExpr GhcPs] -> HsExpr GhcPs) -> [HsExpr GhcPs]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> [HsExpr GhcPs] -> HsExpr GhcPs
exprListToHsApp
                [HsExpr GhcPs]
-> (HsExpr GhcPs -> Change (HsExpr GhcPs))
-> [Change (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\HsExpr GhcPs
c -> ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change
                    (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr)
                    [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
c]
                    SrcSpan
loc
                    []
                    String
"The order of the arguments is invalid."
                    ChangeType
Terminal
                )
            -- Insert Parameter
            paramInsert :: [Change (HsExpr GhcPs)]
paramInsert = [HsExpr GhcPs] -> [([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [HsExpr GhcPs]
paramList
                [([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])]
-> (([HsExpr GhcPs], HsExpr GhcPs, [HsExpr GhcPs])
    -> Change (HsExpr GhcPs))
-> [Change (HsExpr GhcPs)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([HsExpr GhcPs]
h, HsExpr GhcPs
e, [HsExpr GhcPs]
t) -> ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change
                    (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
expr)
                    [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node ([HsExpr GhcPs] -> HsExpr GhcPs
exprListToHsApp ([HsExpr GhcPs]
h [HsExpr GhcPs] -> [HsExpr GhcPs] -> [HsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++ [HsExpr GhcPs
e, HsExpr GhcPs
undefinedExpression] [HsExpr GhcPs] -> [HsExpr GhcPs] -> [HsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++ [HsExpr GhcPs]
t))]
                    SrcSpan
loc
                    []
                    String
"An argument is missing in the function application. Check the number of expected arguments."
                    ChangeType
Addition
                )
            paramList :: [HsExpr GhcPs]
paramList = HsExpr GhcPs -> [HsExpr GhcPs]
hsAppToList HsExpr GhcPs
expr
    -- `let _ = xx in ...` expressions
#if MIN_VERSION_ghc(9,4,1)
    (HsLet XLet GhcPs
x LHsToken "let" GhcPs
letToken HsLocalBinds GhcPs
bind LHsToken "in" GhcPs
inToken LHsExpr GhcPs
e) -> [Change (HsExpr GhcPs)]
enumExpr [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumBind
#else
    (HsLet x bind e) -> enumExpr ++ enumBind
#endif
        where
            enumBind :: [Change (HsExpr GhcPs)]
enumBind = Enumerator (HsLocalBinds GhcPs)
enumerateChangesInLocalBinds HsLocalBinds GhcPs
bind SrcSpan
loc
#if MIN_VERSION_ghc(9,4,1)
                [Change (HsLocalBinds GhcPs)]
-> (HsLocalBinds GhcPs -> HsExpr GhcPs) -> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\HsLocalBinds GhcPs
newbind -> XLet GhcPs
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> LHsExpr GhcPs
-> HsExpr GhcPs
forall p.
XLet p
-> LHsToken "let" p
-> HsLocalBinds p
-> LHsToken "in" p
-> LHsExpr p
-> HsExpr p
HsLet XLet GhcPs
x LHsToken "let" GhcPs
letToken HsLocalBinds GhcPs
newbind LHsToken "in" GhcPs
inToken LHsExpr GhcPs
e)
#else
                <&&> (\newbind -> HsLet x newbind e)
#endif
            enumExpr :: [Change (HsExpr GhcPs)]
enumExpr = let (L SrcAnn AnnListItem
lexpr HsExpr GhcPs
letExpr) = LHsExpr GhcPs
e in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
letExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lexpr)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lexpr)
#if MIN_VERSION_ghc(9,4,1)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XLet GhcPs
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> LHsExpr GhcPs
-> HsExpr GhcPs
forall p.
XLet p
-> LHsToken "let" p
-> HsLocalBinds p
-> LHsToken "in" p
-> LHsExpr p
-> HsExpr p
HsLet XLet GhcPs
x LHsToken "let" GhcPs
letToken HsLocalBinds GhcPs
bind LHsToken "in" GhcPs
inToken)
#else
                <&&> (HsLet x bind)
#endif
                
    (HsIf XIf GhcPs
ext LHsExpr GhcPs
lifExpr LHsExpr GhcPs
lthenExpr LHsExpr GhcPs
lelseExpr) -> [Change (HsExpr GhcPs)]
enumIf [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumElse [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumThen
        where
            enumIf :: [Change (HsExpr GhcPs)]
enumIf = let (L SrcAnn AnnListItem
lif HsExpr GhcPs
ifExpr) = LHsExpr GhcPs
lifExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
ifExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lif)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lif)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newIf -> XIf GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XIf p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsIf XIf GhcPs
ext LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newIf LHsExpr GhcPs
lthenExpr LHsExpr GhcPs
lelseExpr)
            enumElse :: [Change (HsExpr GhcPs)]
enumElse = let (L SrcAnn AnnListItem
lelse HsExpr GhcPs
elseExpr) = LHsExpr GhcPs
lelseExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
elseExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lelse)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lelse)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XIf GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XIf p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsIf XIf GhcPs
ext LHsExpr GhcPs
lifExpr LHsExpr GhcPs
lthenExpr)
            enumThen :: [Change (HsExpr GhcPs)]
enumThen = let (L SrcAnn AnnListItem
lthen HsExpr GhcPs
thenExpr) = LHsExpr GhcPs
lthenExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
thenExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lthen)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lthen)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newthen -> XIf GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XIf p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsIf XIf GhcPs
ext LHsExpr GhcPs
lifExpr LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newthen LHsExpr GhcPs
lelseExpr)
    (HsCase XCase GhcPs
xcase LHsExpr GhcPs
lrootExpr MatchGroup GhcPs (LHsExpr GhcPs)
lmatchExpr) -> [Change (HsExpr GhcPs)]
enumRoot [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumMatches
        where
            enumRoot :: [Change (HsExpr GhcPs)]
enumRoot = let (L SrcAnn AnnListItem
lroot HsExpr GhcPs
root) = LHsExpr GhcPs
lrootExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
root (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lroot)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lroot)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newRoot -> XCase GhcPs
-> LHsExpr GhcPs
-> MatchGroup GhcPs (LHsExpr GhcPs)
-> HsExpr GhcPs
forall p.
XCase p -> LHsExpr p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsCase XCase GhcPs
xcase LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newRoot MatchGroup GhcPs (LHsExpr GhcPs)
lmatchExpr)
            enumMatches :: [Change (HsExpr GhcPs)]
enumMatches = let
#if MIN_VERSION_ghc(9,6,1)
                (MG xmatch (L lmatches matches)) = lmatchExpr
#else
                (MG XMG GhcPs (LHsExpr GhcPs)
xmatch (L SrcSpanAnnL
lmatches [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
matches) Origin
origin) = MatchGroup GhcPs (LHsExpr GhcPs)
lmatchExpr
#endif
                in [[Change (HsExpr GhcPs)]] -> [Change (HsExpr GhcPs)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [([GenLocated
        (SrcAnn AnnListItem)
        (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
     GenLocated
       (SrcAnn AnnListItem)
       (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
     [GenLocated
        (SrcAnn AnnListItem)
        (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
matches
                    [([GenLocated
     (SrcAnn AnnListItem)
     (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
  GenLocated
    (SrcAnn AnnListItem)
    (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
  [GenLocated
     (SrcAnn AnnListItem)
     (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
-> (([GenLocated
        (SrcAnn AnnListItem)
        (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
     GenLocated
       (SrcAnn AnnListItem)
       (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
     [GenLocated
        (SrcAnn AnnListItem)
        (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
    -> [Change (HsExpr GhcPs)])
-> [[Change (HsExpr GhcPs)]]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
h, L SrcAnn AnnListItem
lmatch Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
match, [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
t) -> Enumerator (Match GhcPs (LHsExpr GhcPs))
enumerateChangesInMatch Match GhcPs (LHsExpr GhcPs)
Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
match (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lmatch)
                            [Change
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
    -> GenLocated
         (SrcAnn AnnListItem)
         (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))))
-> [Change
      (GenLocated
         (SrcAnn AnnListItem)
         (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> GenLocated
     (SrcAnn AnnListItem)
     (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lmatch)
                            [Change
   (GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))))]
-> (GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
    -> [GenLocated
          (SrcAnn AnnListItem)
          (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
-> [Change
      [GenLocated
         (SrcAnn AnnListItem)
         (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated
  (SrcAnn AnnListItem)
  (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
newMatch -> [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
h [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
  (SrcAnn AnnListItem)
  (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
newMatch] [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
   (SrcAnn AnnListItem)
   (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
t)
                            [Change
   [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]
-> ([GenLocated
       (SrcAnn AnnListItem)
       (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
    -> GenLocated
         SrcSpanAnnL
         [GenLocated
            (SrcAnn AnnListItem)
            (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
-> [Change
      (GenLocated
         SrcSpanAnnL
         [GenLocated
            (SrcAnn AnnListItem)
            (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcSpanAnnL
-> [GenLocated
      (SrcAnn AnnListItem)
      (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        (SrcAnn AnnListItem)
        (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lmatches)
#if MIN_VERSION_ghc(9,6,1)
                            <&&> (MG xmatch)
#else
                            [Change
   (GenLocated
      SrcSpanAnnL
      [GenLocated
         (SrcAnn AnnListItem)
         (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
-> (GenLocated
      SrcSpanAnnL
      [GenLocated
         (SrcAnn AnnListItem)
         (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
    -> MatchGroup
         GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
-> [Change
      (MatchGroup
         GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated
  SrcSpanAnnL
  [GenLocated
     (SrcAnn AnnListItem)
     (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
newMatches -> XMG GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> XRec
     GhcPs
     [LMatch GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> Origin
-> MatchGroup
     GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
forall p body.
XMG p body -> XRec p [LMatch p body] -> Origin -> MatchGroup p body
MG XMG GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
NoExtField
xmatch XRec
  GhcPs
  [LMatch GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
GenLocated
  SrcSpanAnnL
  [GenLocated
     (SrcAnn AnnListItem)
     (Match GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
newMatches Origin
origin)
#endif
                            [Change
   (MatchGroup
      GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> (MatchGroup
      GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
    -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XCase GhcPs
-> LHsExpr GhcPs
-> MatchGroup GhcPs (LHsExpr GhcPs)
-> HsExpr GhcPs
forall p.
XCase p -> LHsExpr p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsCase XCase GhcPs
xcase LHsExpr GhcPs
lrootExpr)
                    ))
    (OpApp XOpApp GhcPs
xapp LHsExpr GhcPs
lleftExpr LHsExpr GhcPs
lopExpr LHsExpr GhcPs
lrightExpr) -> [Change (HsExpr GhcPs)]
enumLeft [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumOp [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [Change (HsExpr GhcPs)]
enumRight
        where
            enumLeft :: [Change (HsExpr GhcPs)]
enumLeft = let (L SrcAnn AnnListItem
lleft HsExpr GhcPs
leftExpr) = LHsExpr GhcPs
lleftExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
leftExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lleft)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lleft)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newLeft -> XOpApp GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp XOpApp GhcPs
xapp LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newLeft LHsExpr GhcPs
lopExpr LHsExpr GhcPs
lrightExpr)
            enumRight :: [Change (HsExpr GhcPs)]
enumRight = let (L SrcAnn AnnListItem
lright HsExpr GhcPs
rightExpr) = LHsExpr GhcPs
lrightExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
rightExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lright)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lright)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XOpApp GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp XOpApp GhcPs
xapp LHsExpr GhcPs
lleftExpr LHsExpr GhcPs
lopExpr)
            enumOp :: [Change (HsExpr GhcPs)]
enumOp = let (L SrcAnn AnnListItem
lop HsExpr GhcPs
opExpr) = LHsExpr GhcPs
lopExpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
opExpr (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
lop)
                [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
lop)
                [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newOp -> XOpApp GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp XOpApp GhcPs
xapp LHsExpr GhcPs
lleftExpr LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
newOp LHsExpr GhcPs
lrightExpr)
    (NegApp XNegApp GhcPs
xapp LHsExpr GhcPs
lexpr SyntaxExpr GhcPs
syntaxExpr) -> let (L SrcAnn AnnListItem
l HsExpr GhcPs
e) = LHsExpr GhcPs
lexpr in Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
e (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
l)
            [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
l)
            [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs) -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
nexExpt -> XNegApp GhcPs -> LHsExpr GhcPs -> SyntaxExpr GhcPs -> HsExpr GhcPs
forall p. XNegApp p -> LHsExpr p -> SyntaxExpr p -> HsExpr p
NegApp XNegApp GhcPs
xapp LHsExpr GhcPs
GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
nexExpt SyntaxExpr GhcPs
syntaxExpr)
    (HsDo XDo GhcPs
xdo HsDoFlavour
flavor XRec GhcPs [ExprLStmt GhcPs]
llstmts) -> let (L SrcSpanAnnL
ll [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
lstmts) = XRec GhcPs [ExprLStmt GhcPs]
llstmts in [[Change
    [GenLocated
       (SrcAnn AnnListItem)
       (StmtLR
          GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]]
-> [Change
      [GenLocated
         (SrcAnn AnnListItem)
         (StmtLR
            GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [([GenLocated
        (SrcAnn AnnListItem)
        (StmtLR
           GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
     GenLocated
       (SrcAnn AnnListItem)
       (StmtLR
          GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
     [GenLocated
        (SrcAnn AnnListItem)
        (StmtLR
           GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
forall a. [a] -> [([a], a, [a])]
splitEverywhere [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
lstmts [([GenLocated
     (SrcAnn AnnListItem)
     (StmtLR
        GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
  GenLocated
    (SrcAnn AnnListItem)
    (StmtLR
       GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
  [GenLocated
     (SrcAnn AnnListItem)
     (StmtLR
        GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])]
-> (([GenLocated
        (SrcAnn AnnListItem)
        (StmtLR
           GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))],
     GenLocated
       (SrcAnn AnnListItem)
       (StmtLR
          GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))),
     [GenLocated
        (SrcAnn AnnListItem)
        (StmtLR
           GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
    -> [Change
          [GenLocated
             (SrcAnn AnnListItem)
             (StmtLR
                GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]])
-> [[Change
       [GenLocated
          (SrcAnn AnnListItem)
          (StmtLR
             GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\([GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
h, (L SrcAnn AnnListItem
l StmtLR GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
stmt), [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
t) -> case StmtLR GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
stmt of
        BodyStmt XBodyStmt
  GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
xbody (L SrcAnn AnnListItem
le HsExpr GhcPs
e) SyntaxExpr GhcPs
s1 SyntaxExpr GhcPs
s2 -> (Enumerator (HsExpr GhcPs)
enumerateChangesInExpression HsExpr GhcPs
e (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
le) [Change (HsExpr GhcPs)]
-> [Change (HsExpr GhcPs)] -> [Change (HsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ (
            -- If it is the last expression in the body, try to call `return`
            [ChangeNode (HsExpr GhcPs)
-> [ChangeNode (HsExpr GhcPs)]
-> SrcSpan
-> [Change (HsExpr GhcPs)]
-> String
-> ChangeType
-> Change (HsExpr GhcPs)
forall node.
ChangeNode node
-> [ChangeNode node]
-> SrcSpan
-> [Change node]
-> String
-> ChangeType
-> Change node
Change (HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node HsExpr GhcPs
e) [HsExpr GhcPs -> ChangeNode (HsExpr GhcPs)
forall n. Outputable n => n -> ChangeNode n
node (XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
le (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ String -> HsExpr GhcPs
buildFunctionName String
"return") (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
le HsExpr GhcPs
e))] (SrcAnn AnnListItem -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn AnnListItem
le) []
                String
"The type of the expression is correct, but it was not wrapped in the monad." ChangeType
Terminal | [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
t]
            ))
            [Change (HsExpr GhcPs)]
-> (HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (SrcAnn AnnListItem
-> HsExpr GhcPs -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
le)
            [Change (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))]
-> (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
    -> StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
-> [Change
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
n -> XBodyStmt
  GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
-> SyntaxExpr GhcPs
-> SyntaxExpr GhcPs
-> StmtLR
     GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt XBodyStmt
  GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
xbody GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
n SyntaxExpr GhcPs
s1 SyntaxExpr GhcPs
s2)
            [Change
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
    -> [GenLocated
          (SrcAnn AnnListItem)
          (StmtLR
             GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
-> [Change
      [GenLocated
         (SrcAnn AnnListItem)
         (StmtLR
            GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (\StmtLR GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
n -> [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
h [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [SrcAnn AnnListItem
-> StmtLR
     GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> GenLocated
     (SrcAnn AnnListItem)
     (StmtLR
        GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))
forall l e. l -> e -> GenLocated l e
L SrcAnn AnnListItem
l StmtLR GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
n] [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
   (SrcAnn AnnListItem)
   (StmtLR
      GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
t)
        StmtLR GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
_ -> []
        ))
        [Change
   [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]]
-> ([GenLocated
       (SrcAnn AnnListItem)
       (StmtLR
          GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
    -> HsExpr GhcPs)
-> [Change (HsExpr GhcPs)]
forall a b. [Change a] -> (a -> b) -> [Change b]
<&&> (XDo GhcPs
-> HsDoFlavour -> XRec GhcPs [ExprLStmt GhcPs] -> HsExpr GhcPs
forall p. XDo p -> HsDoFlavour -> XRec p [ExprLStmt p] -> HsExpr p
HsDo XDo GhcPs
xdo HsDoFlavour
flavor (GenLocated
   SrcSpanAnnL
   [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
 -> HsExpr GhcPs)
-> ([GenLocated
       (SrcAnn AnnListItem)
       (StmtLR
          GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
    -> GenLocated
         SrcSpanAnnL
         [GenLocated
            (SrcAnn AnnListItem)
            (StmtLR
               GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))])
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> HsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnL
-> [GenLocated
      (SrcAnn AnnListItem)
      (StmtLR
         GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        (SrcAnn AnnListItem)
        (StmtLR
           GhcPs GhcPs (GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)))]
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
ll)
    HsExpr GhcPs
_ -> []

-- | Expression for `undefined`
undefinedExpression :: HsExpr GhcPs
undefinedExpression :: HsExpr GhcPs
undefinedExpression = String -> HsExpr GhcPs
buildFunctionName String
"undefined"

-- | Expression for `[]`
emptyListExpression :: HsExpr GhcPs
emptyListExpression :: HsExpr GhcPs
emptyListExpression = XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed []

-- | Expression for `()`
unitExpression :: HsExpr GhcPs
unitExpression :: HsExpr GhcPs
unitExpression = XExplicitTuple GhcPs -> [HsTupArg GhcPs] -> Boxity -> HsExpr GhcPs
forall p. XExplicitTuple p -> [HsTupArg p] -> Boxity -> HsExpr p
ExplicitTuple XExplicitTuple GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed [] Boxity
Boxed

-- | Build HsExpr (HsVar) from a symbol name
buildFunctionName :: String -> HsExpr GhcPs
buildFunctionName :: String -> HsExpr GhcPs
buildFunctionName String
funcName = XVar GhcPs -> LIdP GhcPs -> HsExpr GhcPs
forall p. XVar p -> LIdP p -> HsExpr p
HsVar XVar GhcPs
NoExtField
NoExtField (LIdP GhcPs -> HsExpr GhcPs) -> LIdP GhcPs -> HsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnN -> RdrName -> GenLocated SrcSpanAnnN RdrName
forall l e. l -> e -> GenLocated l e
L (SrcSpan -> SrcSpanAnnN
forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
noSrcSpan) (OccName -> RdrName
mkRdrUnqual (String -> OccName
mkVarOcc String
funcName))

-- | Wraps an expression in parenthesis (AST-wise).
-- Mainly used for pretty printing
wrapExprInPar :: LHsExpr GhcPs -> HsExpr GhcPs
#if MIN_VERSION_ghc(9,4,1)
wrapExprInPar :: LHsExpr GhcPs -> HsExpr GhcPs
wrapExprInPar LHsExpr GhcPs
e = XPar GhcPs
-> LHsToken "(" GhcPs
-> LHsExpr GhcPs
-> LHsToken ")" GhcPs
-> HsExpr GhcPs
forall p.
XPar p -> LHsToken "(" p -> LHsExpr p -> LHsToken ")" p -> HsExpr p
HsPar XPar GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (TokenLocation
-> HsToken "(" -> GenLocated TokenLocation (HsToken "(")
forall l e. l -> e -> GenLocated l e
L TokenLocation
NoTokenLoc HsToken "("
forall (tok :: Symbol). HsToken tok
HsTok) LHsExpr GhcPs
e (TokenLocation
-> HsToken ")" -> GenLocated TokenLocation (HsToken ")")
forall l e. l -> e -> GenLocated l e
L TokenLocation
NoTokenLoc HsToken ")"
forall (tok :: Symbol). HsToken tok
HsTok)
#else
wrapExprInPar = HsPar EpAnnNotUsed
#endif

-- | Turns an HsApp into a list of expression.
-- `const 1 2` -> [cons, 1, 2]
hsAppToList :: (HsExpr GhcPs) -> [HsExpr GhcPs]
hsAppToList :: HsExpr GhcPs -> [HsExpr GhcPs]
hsAppToList (HsApp XApp GhcPs
_ (L SrcAnn AnnListItem
_ HsExpr GhcPs
func) (L SrcAnn AnnListItem
_ HsExpr GhcPs
param)) = HsExpr GhcPs -> [HsExpr GhcPs]
hsAppToList HsExpr GhcPs
func [HsExpr GhcPs] -> [HsExpr GhcPs] -> [HsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++ [HsExpr GhcPs
param]
hsAppToList HsExpr GhcPs
e = [HsExpr GhcPs
e]

-- | Turns a list of expressions into a function application.
-- [cons, 1, 2] -> `cons 1 2`
exprListToHsApp :: [HsExpr GhcPs] -> (HsExpr GhcPs)
exprListToHsApp :: [HsExpr GhcPs] -> HsExpr GhcPs
exprListToHsApp [] = HsExpr GhcPs
forall a. HasCallStack => a
undefined
exprListToHsApp [HsExpr GhcPs
f, HsExpr GhcPs
p] = XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall e ann. Located e -> LocatedAn ann e
reLocA (Located (HsExpr GhcPs)
 -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ HsExpr GhcPs -> Located (HsExpr GhcPs)
forall e. e -> Located e
noLoc HsExpr GhcPs
f) (Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall e ann. Located e -> LocatedAn ann e
reLocA (Located (HsExpr GhcPs)
 -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ HsExpr GhcPs -> Located (HsExpr GhcPs)
forall e. e -> Located e
noLoc HsExpr GhcPs
p)
exprListToHsApp [HsExpr GhcPs
e] = HsExpr GhcPs
e
exprListToHsApp [HsExpr GhcPs]
list = XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall e ann. Located e -> LocatedAn ann e
reLocA (Located (HsExpr GhcPs)
 -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ HsExpr GhcPs -> Located (HsExpr GhcPs)
forall e. e -> Located e
noLoc (HsExpr GhcPs -> Located (HsExpr GhcPs))
-> HsExpr GhcPs -> Located (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ [HsExpr GhcPs] -> HsExpr GhcPs
exprListToHsApp ([HsExpr GhcPs] -> [HsExpr GhcPs]
forall a. HasCallStack => [a] -> [a]
init [HsExpr GhcPs]
list)) (Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall e ann. Located e -> LocatedAn ann e
reLocA (Located (HsExpr GhcPs)
 -> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs))
-> Located (HsExpr GhcPs)
-> GenLocated (SrcAnn AnnListItem) (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ HsExpr GhcPs -> Located (HsExpr GhcPs)
forall e. e -> Located e
noLoc (HsExpr GhcPs -> Located (HsExpr GhcPs))
-> HsExpr GhcPs -> Located (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ [HsExpr GhcPs] -> HsExpr GhcPs
forall a. HasCallStack => [a] -> a
last [HsExpr GhcPs]
list)