{-# LANGUAGE CPP #-}
module Development.IDE.Plugin.Plugins.AddArgument (plugin) where

#if MIN_VERSION_ghc(9,4,0)
import           Development.IDE.GHC.ExactPrint            (epl)
import           GHC.Parser.Annotation                     (TokenLocation (..))
#endif
#if !MIN_VERSION_ghc(9,2,1)
import qualified Data.Text                                 as T
import           Language.LSP.Types
#else
import           Control.Monad                             (join)
import           Control.Monad.Trans.Class                 (lift)
import           Data.Bifunctor                            (Bifunctor (..))
import           Data.Either.Extra                         (maybeToEither)
import qualified Data.Text                                 as T
import           Development.IDE.GHC.Compat
import           Development.IDE.GHC.Compat.ExactPrint     (exactPrint,
                                                            makeDeltaAst)
import           Development.IDE.GHC.Error                 (spanContainsRange)
import           Development.IDE.GHC.ExactPrint            (genAnchor1,
                                                            modifyMgMatchesT',
                                                            modifySigWithM,
                                                            modifySmallestDeclWithM)
import           Development.IDE.Plugin.Plugins.Diagnostic
import           GHC                                       (EpAnn (..),
                                                            SrcSpanAnn' (SrcSpanAnn),
                                                            SrcSpanAnnA,
                                                            SrcSpanAnnN,
                                                            TrailingAnn (..),
                                                            emptyComments,
                                                            noAnn)
import           GHC.Hs                                    (IsUnicodeSyntax (..))
import           GHC.Types.SrcLoc                          (generatedSrcSpan)
import           Ide.PluginUtils                           (makeDiffTextEdit,
                                                            responseError)
import           Language.Haskell.GHC.ExactPrint           (TransformT(..),
                                                            noAnnSrcSpanDP1,
                                                            runTransformT)
import           Language.Haskell.GHC.ExactPrint.Transform (d1)
import           Language.LSP.Types
#endif

#if !MIN_VERSION_ghc(9,2,1)
plugin :: [(T.Text, [TextEdit])]
plugin = []
#else
-- When GHC tells us that a variable is not bound, it will tell us either:
--  - there is an unbound variable with a given type
--  - there is an unbound variable (GHC provides no type suggestion)
--
-- When we receive either of these errors, we produce a text edit that will add a new argument (as a new pattern in the
-- last position of each LHS of the top-level bindings for this HsDecl).
--
-- NOTE When adding a new argument to a declaration, the corresponding argument's type in declaration's signature might
--      not be the last type in the signature, such as:
--         foo :: a -> b -> c -> d
--         foo a b = \c -> ...
--      In this case a new argument would have to add its type between b and c in the signature.
plugin :: ParsedModule -> Diagnostic -> Either ResponseError [(T.Text, [TextEdit])]
plugin :: ParsedModule
-> Diagnostic -> Either ResponseError [(Text, [TextEdit])]
plugin ParsedModule
parsedModule Diagnostic {Text
$sel:_message:Diagnostic :: Diagnostic -> Text
_message :: Text
_message, Range
$sel:_range:Diagnostic :: Diagnostic -> Range
_range :: Range
_range}
  | Just (Text
name, Maybe Text
typ) <- Text -> Maybe (Text, Maybe Text)
matchVariableNotInScope Text
message = ParsedModule
-> Range
-> Text
-> Maybe Text
-> Either ResponseError [(Text, [TextEdit])]
addArgumentAction ParsedModule
parsedModule Range
_range Text
name Maybe Text
typ
  | Just (Text
name, Text
typ) <- Text -> Maybe (Text, Text)
matchFoundHoleIncludeUnderscore Text
message = ParsedModule
-> Range
-> Text
-> Maybe Text
-> Either ResponseError [(Text, [TextEdit])]
addArgumentAction ParsedModule
parsedModule Range
_range Text
name (forall a. a -> Maybe a
Just Text
typ)
  | Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  where
    message :: Text
message = Text -> Text
unifySpaces Text
_message

-- Given a name for the new binding, add a new pattern to the match in the last position,
-- returning how many patterns there were in this match prior to the transformation:
--      addArgToMatch "foo" `bar arg1 arg2 = ...`
--   => (`bar arg1 arg2 foo = ...`, 2)
addArgToMatch :: T.Text -> GenLocated l (Match GhcPs body) -> (GenLocated l (Match GhcPs body), Int)
addArgToMatch :: forall l body.
Text
-> GenLocated l (Match GhcPs body)
-> (GenLocated l (Match GhcPs body), Int)
addArgToMatch Text
name (L l
locMatch (Match XCMatch GhcPs body
xMatch HsMatchContext (NoGhcTc GhcPs)
ctxMatch [LPat GhcPs]
pats GRHSs GhcPs body
rhs)) =
  let unqualName :: RdrName
unqualName = OccName -> RdrName
mkRdrUnqual forall a b. (a -> b) -> a -> b
$ String -> OccName
mkVarOcc forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
name
      newPat :: GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (Pat GhcPs)
newPat = forall l e. l -> e -> GenLocated l e
L (forall ann. Monoid ann => SrcSpan -> SrcSpanAnn' (EpAnn ann)
noAnnSrcSpanDP1 SrcSpan
generatedSrcSpan) forall a b. (a -> b) -> a -> b
$ forall p. XVarPat p -> LIdP p -> Pat p
VarPat NoExtField
NoExtField (forall a an. a -> LocatedAn an a
noLocA RdrName
unqualName)
  in (forall l e. l -> e -> GenLocated l e
L l
locMatch (forall p body.
XCMatch p body
-> HsMatchContext (NoGhcTc p)
-> [LPat p]
-> GRHSs p body
-> Match p body
Match XCMatch GhcPs body
xMatch HsMatchContext (NoGhcTc GhcPs)
ctxMatch ([LPat GhcPs]
pats forall a. Semigroup a => a -> a -> a
<> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (Pat GhcPs)
newPat]) GRHSs GhcPs body
rhs), forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [LPat GhcPs]
pats)

-- Attempt to insert a binding pattern into each match for the given LHsDecl; succeeds only if the function is a FunBind.
-- Also return:
--   - the declaration's name
--   - the number of bound patterns in the declaration's matches prior to the transformation
--
-- For example:
--    insertArg "new_pat" `foo bar baz = 1`
-- => (`foo bar baz new_pat = 1`, Just ("foo", 2))
appendFinalPatToMatches :: T.Text -> LHsDecl GhcPs -> TransformT (Either ResponseError) (LHsDecl GhcPs, Maybe (GenLocated SrcSpanAnnN RdrName, Int))
appendFinalPatToMatches :: Text
-> LHsDecl GhcPs
-> TransformT
     (Either ResponseError)
     (LHsDecl GhcPs, Maybe (GenLocated SrcSpanAnnN RdrName, Int))
appendFinalPatToMatches Text
name = \case
  (L SrcSpanAnn' (EpAnn AnnListItem)
locDecl (ValD XValD GhcPs
xVal fun :: HsBind GhcPs
fun@FunBind{fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches=MatchGroup GhcPs (LHsExpr GhcPs)
mg,fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP GhcPs
idFunBind})) -> do
    (MatchGroup
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsExpr GhcPs))
mg', Maybe Int
numPatsMay) <- forall (m :: * -> *) r.
Monad m =>
MatchGroup GhcPs (LHsExpr GhcPs)
-> (LMatch GhcPs (LHsExpr GhcPs)
    -> TransformT m (LMatch GhcPs (LHsExpr GhcPs), r))
-> r
-> (r -> r -> m r)
-> TransformT m (MatchGroup GhcPs (LHsExpr GhcPs), r)
modifyMgMatchesT' MatchGroup GhcPs (LHsExpr GhcPs)
mg (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l body.
Text
-> GenLocated l (Match GhcPs body)
-> (GenLocated l (Match GhcPs body), Int)
addArgToMatch Text
name) forall a. Maybe a
Nothing forall {a}.
Eq a =>
Maybe a -> Maybe a -> Either ResponseError (Maybe a)
combineMatchNumPats
    Int
numPats <- forall (m :: * -> *) a. RWST () [String] Int m a -> TransformT m a
TransformT forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a b. a -> Maybe b -> Either a b
maybeToEither (Text -> ResponseError
responseError Text
"Unexpected empty match group in HsDecl") Maybe Int
numPatsMay
    let decl' :: GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
decl' = forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
locDecl (forall p. XValD p -> HsBind p -> HsDecl p
ValD XValD GhcPs
xVal HsBind GhcPs
fun{fun_matches :: MatchGroup GhcPs (LHsExpr GhcPs)
fun_matches=MatchGroup
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsExpr GhcPs))
mg'})
    forall (f :: * -> *) a. Applicative f => a -> f a
pure (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
decl', forall a. a -> Maybe a
Just (LIdP GhcPs
idFunBind, Int
numPats))
  LHsDecl GhcPs
decl -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsDecl GhcPs
decl, forall a. Maybe a
Nothing)
  where
    combineMatchNumPats :: Maybe a -> Maybe a -> Either ResponseError (Maybe a)
combineMatchNumPats  Maybe a
Nothing Maybe a
other = forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
other
    combineMatchNumPats  Maybe a
other Maybe a
Nothing = forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
other
    combineMatchNumPats  (Just a
l) (Just a
r)
      | a
l forall a. Eq a => a -> a -> Bool
== a
r = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. a -> Maybe a
Just a
l)
      | Bool
otherwise = forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Text -> ResponseError
responseError Text
"Unexpected different numbers of patterns in HsDecl MatchGroup"

-- The add argument works as follows:
--  1. Attempt to add the given name as the last pattern of the declaration that contains `range`.
--  2. If such a declaration exists, use that declaration's name to modify the signature of said declaration, if it
--     has a type signature.
--
-- NOTE For the following situation, the type signature is not updated (it's unclear what should happen):
--   type FunctionTySyn = () -> Int
--   foo :: FunctionTySyn
--   foo () = new_def
--
-- TODO instead of inserting a typed hole; use GHC's suggested type from the error
addArgumentAction :: ParsedModule -> Range -> T.Text -> Maybe T.Text -> Either ResponseError [(T.Text, [TextEdit])]
addArgumentAction :: ParsedModule
-> Range
-> Text
-> Maybe Text
-> Either ResponseError [(Text, [TextEdit])]
addArgumentAction (ParsedModule ModSummary
_ ParsedSource
moduleSrc [String]
_ ()
_) Range
range Text
name Maybe Text
_typ = do
    (ParsedSource
newSource, Int
_, [String]
_) <- forall (m :: * -> *) a. TransformT m a -> m (a, Int, [String])
runTransformT forall a b. (a -> b) -> a -> b
$ do
      (ParsedSource
moduleSrc', forall (m :: * -> *) a. Monad m => m (m a) -> m a
join -> Maybe (GenLocated SrcSpanAnnN RdrName, Int)
matchedDeclNameMay) <- ParsedSource
-> TransformT
     (Either ResponseError)
     (ParsedSource, Maybe (Maybe (GenLocated SrcSpanAnnN RdrName, Int)))
addNameAsLastArgOfMatchingDecl (forall ast. ExactPrint ast => ast -> ast
makeDeltaAst ParsedSource
moduleSrc)
      case Maybe (GenLocated SrcSpanAnnN RdrName, Int)
matchedDeclNameMay of
          Just (GenLocated SrcSpanAnnN RdrName
matchedDeclName, Int
numPats) -> forall a (m :: * -> *).
(HasDecls a, Monad m) =>
IdP GhcPs
-> (LHsSigType GhcPs -> LHsSigType GhcPs) -> a -> TransformT m a
modifySigWithM (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
matchedDeclName) (Int -> LHsSigType GhcPs -> LHsSigType GhcPs
addTyHoleToTySigArg Int
numPats) ParsedSource
moduleSrc'
          Maybe (GenLocated SrcSpanAnnN RdrName, Int)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ParsedSource
moduleSrc'
    let diff :: List TextEdit
diff = Text -> Text -> List TextEdit
makeDiffTextEdit (String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall ast. ExactPrint ast => ast -> String
exactPrint ParsedSource
moduleSrc) (String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall ast. ExactPrint ast => ast -> String
exactPrint ParsedSource
newSource)
    forall (f :: * -> *) a. Applicative f => a -> f a
pure [(Text
"Add argument ‘" forall a. Semigroup a => a -> a -> a
<> Text
name forall a. Semigroup a => a -> a -> a
<> Text
"’ to function", forall a. List a -> [a]
fromLspList List TextEdit
diff)]
  where
    addNameAsLastArgOfMatchingDecl :: ParsedSource
-> TransformT
     (Either ResponseError)
     (ParsedSource, Maybe (Maybe (GenLocated SrcSpanAnnN RdrName, Int)))
addNameAsLastArgOfMatchingDecl = forall a (m :: * -> *) r.
(HasDecls a, Monad m) =>
(SrcSpan -> m Bool)
-> (LHsDecl GhcPs -> TransformT m ([LHsDecl GhcPs], r))
-> a
-> TransformT m (a, Maybe r)
modifySmallestDeclWithM SrcSpan -> Either ResponseError Bool
spanContainsRangeOrErr GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> TransformT
     (Either ResponseError)
     ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
      Maybe (GenLocated SrcSpanAnnN RdrName, Int))
addNameAsLastArg
    addNameAsLastArg :: GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> TransformT
     (Either ResponseError)
     ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
      Maybe (GenLocated SrcSpanAnnN RdrName, Int))
addNameAsLastArg = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (forall a. a -> [a] -> [a]
:[])) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> LHsDecl GhcPs
-> TransformT
     (Either ResponseError)
     (LHsDecl GhcPs, Maybe (GenLocated SrcSpanAnnN RdrName, Int))
appendFinalPatToMatches Text
name

    spanContainsRangeOrErr :: SrcSpan -> Either ResponseError Bool
spanContainsRangeOrErr = forall a b. a -> Maybe b -> Either a b
maybeToEither (Text -> ResponseError
responseError Text
"SrcSpan was not valid range") forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SrcSpan -> Range -> Maybe Bool
`spanContainsRange` Range
range)

-- Transform an LHsType into a list of arguments and return type, to make transformations easier.
hsTypeToFunTypeAsList :: LHsType GhcPs -> ([(SrcSpanAnnA, XFunTy GhcPs, HsArrow GhcPs, LHsType GhcPs)], LHsType GhcPs)
hsTypeToFunTypeAsList :: LHsType GhcPs
-> ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
      LHsType GhcPs)],
    LHsType GhcPs)
hsTypeToFunTypeAsList = \case
  L SrcSpanAnn' (EpAnn AnnListItem)
spanAnnA (HsFunTy XFunTy GhcPs
xFunTy HsArrow GhcPs
arrow LHsType GhcPs
lhs LHsType GhcPs
rhs) ->
    let ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
  LHsType GhcPs)]
rhsArgs, LHsType GhcPs
rhsRes) = LHsType GhcPs
-> ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
      LHsType GhcPs)],
    LHsType GhcPs)
hsTypeToFunTypeAsList LHsType GhcPs
rhs
    in ((SrcSpanAnn' (EpAnn AnnListItem)
spanAnnA, XFunTy GhcPs
xFunTy, HsArrow GhcPs
arrow, LHsType GhcPs
lhs)forall a. a -> [a] -> [a]
:[(SrcSpanAnn' (EpAnn AnnListItem), EpAnn TrailingAnn,
  HsArrow GhcPs,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
rhsArgs, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
rhsRes)
  LHsType GhcPs
ty -> ([], LHsType GhcPs
ty)

-- The inverse of `hsTypeToFunTypeAsList`
hsTypeFromFunTypeAsList :: ([(SrcSpanAnnA, XFunTy GhcPs, HsArrow GhcPs, LHsType GhcPs)], LHsType GhcPs) -> LHsType GhcPs
hsTypeFromFunTypeAsList :: ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
   LHsType GhcPs)],
 LHsType GhcPs)
-> LHsType GhcPs
hsTypeFromFunTypeAsList ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
  LHsType GhcPs)]
args, LHsType GhcPs
res) =
  forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(SrcSpanAnn' (EpAnn AnnListItem)
spanAnnA, EpAnn TrailingAnn
xFunTy, HsArrow GhcPs
arrow, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
argTy) GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
res -> forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
spanAnnA forall a b. (a -> b) -> a -> b
$ forall pass.
XFunTy pass
-> HsArrow pass -> LHsType pass -> LHsType pass -> HsType pass
HsFunTy EpAnn TrailingAnn
xFunTy HsArrow GhcPs
arrow GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
argTy GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
res) LHsType GhcPs
res [(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
  LHsType GhcPs)]
args

-- Add a typed hole to a type signature in the given argument position:
--   0 `foo :: ()` => foo :: _ -> ()
--   2 `foo :: FunctionTySyn` => foo :: FunctionTySyn
--   1 `foo :: () -> () -> Int` => foo :: () -> _ -> () -> Int
addTyHoleToTySigArg :: Int -> LHsSigType GhcPs -> (LHsSigType GhcPs)
addTyHoleToTySigArg :: Int -> LHsSigType GhcPs -> LHsSigType GhcPs
addTyHoleToTySigArg Int
loc (L SrcSpanAnn' (EpAnn AnnListItem)
annHsSig (HsSig XHsSig GhcPs
xHsSig HsOuterSigTyVarBndrs GhcPs
tyVarBndrs LHsType GhcPs
lsigTy)) =
    let ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
  LHsType GhcPs)]
args, LHsType GhcPs
res) = LHsType GhcPs
-> ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
      LHsType GhcPs)],
    LHsType GhcPs)
hsTypeToFunTypeAsList LHsType GhcPs
lsigTy
#if MIN_VERSION_ghc(9,4,0)
        wildCardAnn = SrcSpanAnn (EpAnn genAnchor1 (AnnListItem []) emptyComments) generatedSrcSpan
        arrowAnn = TokenLoc (epl 1)
        newArg = (SrcSpanAnn mempty generatedSrcSpan, noAnn, HsUnrestrictedArrow (L arrowAnn HsNormalTok), L wildCardAnn $ HsWildCardTy noExtField)
#else
        wildCardAnn :: SrcSpanAnn' (EpAnn AnnListItem)
wildCardAnn = forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn Anchor
genAnchor1 ([TrailingAnn] -> AnnListItem
AnnListItem [EpaLocation -> TrailingAnn
AddRarrowAnn EpaLocation
d1]) EpAnnComments
emptyComments) SrcSpan
generatedSrcSpan
        newArg :: (SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
 GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
newArg = (forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn forall a. Monoid a => a
mempty SrcSpan
generatedSrcSpan, forall a. EpAnn a
noAnn, forall pass. IsUnicodeSyntax -> HsArrow pass
HsUnrestrictedArrow IsUnicodeSyntax
NormalSyntax, forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
wildCardAnn forall a b. (a -> b) -> a -> b
$ forall pass. XWildCardTy pass -> HsType pass
HsWildCardTy NoExtField
noExtField)
#endif
        -- NOTE if the location that the argument wants to be placed at is not one more than the number of arguments
        --      in the signature, then we return the original type signature.
        --      This situation most likely occurs due to a function type synonym in the signature
        insertArg :: t
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
insertArg t
n [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
_ | t
n forall a. Ord a => a -> a -> Bool
< t
0 = forall a. HasCallStack => String -> a
error String
"Not possible"
        insertArg t
0 [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
as = forall {a} {pass}.
(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
 GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
newArgforall a. a -> [a] -> [a]
:[(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
as
        insertArg t
_ [] = []
        insertArg t
n ((SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
 GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
a:[(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
as) = (SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
 GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
a forall a. a -> [a] -> [a]
: t
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
insertArg (t
n forall a. Num a => a -> a -> a
- t
1) [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
as
        lsigTy' :: LHsType GhcPs
lsigTy' = ([(SrcSpanAnn' (EpAnn AnnListItem), XFunTy GhcPs, HsArrow GhcPs,
   LHsType GhcPs)],
 LHsType GhcPs)
-> LHsType GhcPs
hsTypeFromFunTypeAsList (forall {t} {a} {pass}.
(Ord t, Num t) =>
t
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn a, HsArrow pass,
     GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
insertArg Int
loc [(SrcSpanAnn' (EpAnn AnnListItem), EpAnn TrailingAnn,
  HsArrow GhcPs,
  GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
args, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
res)
    in forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
annHsSig (forall pass.
XHsSig pass
-> HsOuterSigTyVarBndrs pass -> LHsType pass -> HsSigType pass
HsSig XHsSig GhcPs
xHsSig HsOuterSigTyVarBndrs GhcPs
tyVarBndrs GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
lsigTy')

fromLspList :: List a -> [a]
fromLspList :: forall a. List a -> [a]
fromLspList (List [a]
a) = [a]
a
#endif