{-
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

\section[RnPat]{Renaming of patterns}

Basically dependency analysis.

Handles @Match@, @GRHSs@, @HsExpr@, and @Qualifier@ datatypes.  In
general, all of these functions return a renamed thing, and a set of
free variables.
-}

{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}

module RnPat (-- main entry points
              rnPat, rnPats, rnBindPat, rnPatAndThen,

              NameMaker, applyNameMaker,     -- a utility for making names:
              localRecNameMaker, topRecNameMaker,  --   sometimes we want to make local names,
                                             --   sometimes we want to make top (qualified) names.
              isTopRecNameMaker,

              rnHsRecFields, HsRecFieldContext(..),
              rnHsRecUpdFields,

              -- CpsRn monad
              CpsRn, liftCps,

              -- Literals
              rnLit, rnOverLit,

             -- Pattern Error messages that are also used elsewhere
             checkTupSize, patSigErr
             ) where

-- ENH: thin imports to only what is necessary for patterns

import GhcPrelude

import {-# SOURCE #-} RnExpr ( rnLExpr )
import {-# SOURCE #-} RnSplice ( rnSplicePat )

#include "HsVersions.h"

import HsSyn
import TcRnMonad
import TcHsSyn             ( hsOverLitName )
import RnEnv
import RnFixity
import RnUtils             ( HsDocContext(..), newLocalBndrRn, bindLocalNames
                           , warnUnusedMatches, newLocalBndrRn
                           , checkDupNames, checkDupAndShadowedNames
                           , checkTupSize , unknownSubordinateErr )
import RnTypes
import PrelNames
import Name
import NameSet
import RdrName
import BasicTypes
import Util
import ListSetOps          ( removeDups )
import Outputable
import SrcLoc
import Literal             ( inCharRange )
import TysWiredIn          ( nilDataCon )
import DataCon
import qualified GHC.LanguageExtensions as LangExt

import Control.Monad       ( when, liftM, ap, guard )
import qualified Data.List.NonEmpty as NE
import Data.Ratio

{-
*********************************************************
*                                                      *
        The CpsRn Monad
*                                                      *
*********************************************************

Note [CpsRn monad]
~~~~~~~~~~~~~~~~~~
The CpsRn monad uses continuation-passing style to support this
style of programming:

        do { ...
           ; ns <- bindNames rs
           ; ...blah... }

   where rs::[RdrName], ns::[Name]

The idea is that '...blah...'
  a) sees the bindings of ns
  b) returns the free variables it mentions
     so that bindNames can report unused ones

In particular,
    mapM rnPatAndThen [p1, p2, p3]
has a *left-to-right* scoping: it makes the binders in
p1 scope over p2,p3.
-}

newtype CpsRn b = CpsRn { CpsRn b -> forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
unCpsRn :: forall r. (b -> RnM (r, FreeVars))
                                            -> RnM (r, FreeVars) }
        -- See Note [CpsRn monad]

instance Functor CpsRn where
    fmap :: (a -> b) -> CpsRn a -> CpsRn b
fmap = (a -> b) -> CpsRn a -> CpsRn b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM

instance Applicative CpsRn where
    pure :: a -> CpsRn a
pure x :: a
x = (forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn a
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: a -> RnM (r, FreeVars)
k -> a -> RnM (r, FreeVars)
k a
x)
    <*> :: CpsRn (a -> b) -> CpsRn a -> CpsRn b
(<*>) = CpsRn (a -> b) -> CpsRn a -> CpsRn b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

instance Monad CpsRn where
  (CpsRn m :: forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
m) >>= :: CpsRn a -> (a -> CpsRn b) -> CpsRn b
>>= mk :: a -> CpsRn b
mk = (forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: b -> RnM (r, FreeVars)
k -> (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
m (\v :: a
v -> CpsRn b -> (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall b.
CpsRn b -> forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
unCpsRn (a -> CpsRn b
mk a
v) b -> RnM (r, FreeVars)
k))

runCps :: CpsRn a -> RnM (a, FreeVars)
runCps :: CpsRn a -> RnM (a, FreeVars)
runCps (CpsRn m :: forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
m) = (a -> RnM (a, FreeVars)) -> RnM (a, FreeVars)
forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
m (\r :: a
r -> (a, FreeVars) -> RnM (a, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
r, FreeVars
emptyFVs))

liftCps :: RnM a -> CpsRn a
liftCps :: RnM a -> CpsRn a
liftCps rn_thing :: RnM a
rn_thing = (forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn a
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: a -> RnM (r, FreeVars)
k -> RnM a
rn_thing RnM a -> (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> RnM (r, FreeVars)
k)

liftCpsFV :: RnM (a, FreeVars) -> CpsRn a
liftCpsFV :: RnM (a, FreeVars) -> CpsRn a
liftCpsFV rn_thing :: RnM (a, FreeVars)
rn_thing = (forall r. (a -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn a
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: a -> RnM (r, FreeVars)
k -> do { (v :: a
v,fvs1 :: FreeVars
fvs1) <- RnM (a, FreeVars)
rn_thing
                                     ; (r :: r
r,fvs2 :: FreeVars
fvs2) <- a -> RnM (r, FreeVars)
k a
v
                                     ; (r, FreeVars) -> RnM (r, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (r
r, FreeVars
fvs1 FreeVars -> FreeVars -> FreeVars
`plusFV` FreeVars
fvs2) })

wrapSrcSpanCps :: (HasSrcSpan a, HasSrcSpan b) =>
                  (SrcSpanLess a -> CpsRn (SrcSpanLess b)) -> a -> CpsRn b
-- Set the location, and also wrap it around the value returned
wrapSrcSpanCps :: (SrcSpanLess a -> CpsRn (SrcSpanLess b)) -> a -> CpsRn b
wrapSrcSpanCps fn :: SrcSpanLess a -> CpsRn (SrcSpanLess b)
fn (a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc a :: SrcSpanLess a
a)
  = (forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: b -> RnM (r, FreeVars)
k -> SrcSpan -> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (RnM (r, FreeVars) -> RnM (r, FreeVars))
-> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a b. (a -> b) -> a -> b
$
                 CpsRn (SrcSpanLess b)
-> forall r.
   (SrcSpanLess b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall b.
CpsRn b -> forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
unCpsRn (SrcSpanLess a -> CpsRn (SrcSpanLess b)
fn SrcSpanLess a
a) ((SrcSpanLess b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> (SrcSpanLess b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall a b. (a -> b) -> a -> b
$ \v :: SrcSpanLess b
v ->
                 b -> RnM (r, FreeVars)
k (SrcSpan -> SrcSpanLess b -> b
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess b
v))

lookupConCps :: Located RdrName -> CpsRn (Located Name)
lookupConCps :: Located RdrName -> CpsRn (Located Name)
lookupConCps con_rdr :: Located RdrName
con_rdr
  = (forall r.
 (Located Name -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn (Located Name)
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\k :: Located Name -> RnM (r, FreeVars)
k -> do { Located Name
con_name <- Located RdrName -> RnM (Located Name)
lookupLocatedOccRn Located RdrName
con_rdr
                    ; (r :: r
r, fvs :: FreeVars
fvs) <- Located Name -> RnM (r, FreeVars)
k Located Name
con_name
                    ; (r, FreeVars) -> RnM (r, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (r
r, FreeVars -> Name -> FreeVars
addOneFV FreeVars
fvs (Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
con_name)) })
    -- We add the constructor name to the free vars
    -- See Note [Patterns are uses]

{-
Note [Patterns are uses]
~~~~~~~~~~~~~~~~~~~~~~~~
Consider
  module Foo( f, g ) where
  data T = T1 | T2

  f T1 = True
  f T2 = False

  g _ = T1

Arguably we should report T2 as unused, even though it appears in a
pattern, because it never occurs in a constructed position.  See
Trac #7336.
However, implementing this in the face of pattern synonyms would be
less straightforward, since given two pattern synonyms

  pattern P1 <- P2
  pattern P2 <- ()

we need to observe the dependency between P1 and P2 so that type
checking can be done in the correct order (just like for value
bindings). Dependencies between bindings is analyzed in the renamer,
where we don't know yet whether P2 is a constructor or a pattern
synonym. So for now, we do report conid occurrences in patterns as
uses.

*********************************************************
*                                                      *
        Name makers
*                                                      *
*********************************************************

Externally abstract type of name makers,
which is how you go from a RdrName to a Name
-}

data NameMaker
  = LamMk       -- Lambdas
      Bool      -- True <=> report unused bindings
                --   (even if True, the warning only comes out
                --    if -Wunused-matches is on)

  | LetMk       -- Let bindings, incl top level
                -- Do *not* check for unused bindings
      TopLevelFlag
      MiniFixityEnv

topRecNameMaker :: MiniFixityEnv -> NameMaker
topRecNameMaker :: MiniFixityEnv -> NameMaker
topRecNameMaker fix_env :: MiniFixityEnv
fix_env = TopLevelFlag -> MiniFixityEnv -> NameMaker
LetMk TopLevelFlag
TopLevel MiniFixityEnv
fix_env

isTopRecNameMaker :: NameMaker -> Bool
isTopRecNameMaker :: NameMaker -> Bool
isTopRecNameMaker (LetMk TopLevel _) = Bool
True
isTopRecNameMaker _ = Bool
False

localRecNameMaker :: MiniFixityEnv -> NameMaker
localRecNameMaker :: MiniFixityEnv -> NameMaker
localRecNameMaker fix_env :: MiniFixityEnv
fix_env = TopLevelFlag -> MiniFixityEnv -> NameMaker
LetMk TopLevelFlag
NotTopLevel MiniFixityEnv
fix_env

matchNameMaker :: HsMatchContext a -> NameMaker
matchNameMaker :: HsMatchContext a -> NameMaker
matchNameMaker ctxt :: HsMatchContext a
ctxt = Bool -> NameMaker
LamMk Bool
report_unused
  where
    -- Do not report unused names in interactive contexts
    -- i.e. when you type 'x <- e' at the GHCi prompt
    report_unused :: Bool
report_unused = case HsMatchContext a
ctxt of
                      StmtCtxt GhciStmtCtxt -> Bool
False
                      -- also, don't warn in pattern quotes, as there
                      -- is no RHS where the variables can be used!
                      ThPatQuote            -> Bool
False
                      _                     -> Bool
True

rnHsSigCps :: LHsSigWcType GhcPs -> CpsRn (LHsSigWcType GhcRn)
rnHsSigCps :: LHsSigWcType GhcPs -> CpsRn (LHsSigWcType GhcRn)
rnHsSigCps sig :: LHsSigWcType GhcPs
sig = (forall r.
 (LHsSigWcType GhcRn -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn (LHsSigWcType GhcRn)
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (HsSigWcTypeScoping
-> HsDocContext
-> LHsSigWcType GhcPs
-> (LHsSigWcType GhcRn -> RnM (r, FreeVars))
-> RnM (r, FreeVars)
forall a.
HsSigWcTypeScoping
-> HsDocContext
-> LHsSigWcType GhcPs
-> (LHsSigWcType GhcRn -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
rnHsSigWcTypeScoped HsSigWcTypeScoping
AlwaysBind HsDocContext
PatCtx LHsSigWcType GhcPs
sig)

newPatLName :: NameMaker -> Located RdrName -> CpsRn (Located Name)
newPatLName :: NameMaker -> Located RdrName -> CpsRn (Located Name)
newPatLName name_maker :: NameMaker
name_maker rdr_name :: Located RdrName
rdr_name@(Located RdrName -> Located (SrcSpanLess (Located RdrName))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc _)
  = do { Name
name <- NameMaker -> Located RdrName -> CpsRn Name
newPatName NameMaker
name_maker Located RdrName
rdr_name
       ; Located Name -> CpsRn (Located Name)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc Name
SrcSpanLess (Located Name)
name) }

newPatName :: NameMaker -> Located RdrName -> CpsRn Name
newPatName :: NameMaker -> Located RdrName -> CpsRn Name
newPatName (LamMk report_unused :: Bool
report_unused) rdr_name :: Located RdrName
rdr_name
  = (forall r. (Name -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn Name
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\ thing_inside :: Name -> RnM (r, FreeVars)
thing_inside ->
        do { Name
name <- Located RdrName -> RnM Name
newLocalBndrRn Located RdrName
rdr_name
           ; (res :: r
res, fvs :: FreeVars
fvs) <- [Name] -> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a. [Name] -> RnM a -> RnM a
bindLocalNames [Name
name] (Name -> RnM (r, FreeVars)
thing_inside Name
name)
           ; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
report_unused (IOEnv (Env TcGblEnv TcLclEnv) ()
 -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ [Name] -> FreeVars -> IOEnv (Env TcGblEnv TcLclEnv) ()
warnUnusedMatches [Name
name] FreeVars
fvs
           ; (r, FreeVars) -> RnM (r, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (r
res, Name
name Name -> FreeVars -> FreeVars
`delFV` FreeVars
fvs) })

newPatName (LetMk is_top :: TopLevelFlag
is_top fix_env :: MiniFixityEnv
fix_env) rdr_name :: Located RdrName
rdr_name
  = (forall r. (Name -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn Name
forall b.
(forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars))
-> CpsRn b
CpsRn (\ thing_inside :: Name -> RnM (r, FreeVars)
thing_inside ->
        do { Name
name <- case TopLevelFlag
is_top of
                       NotTopLevel -> Located RdrName -> RnM Name
newLocalBndrRn Located RdrName
rdr_name
                       TopLevel    -> Located RdrName -> RnM Name
newTopSrcBinder Located RdrName
rdr_name
           ; [Name] -> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a. [Name] -> RnM a -> RnM a
bindLocalNames [Name
name] (RnM (r, FreeVars) -> RnM (r, FreeVars))
-> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a b. (a -> b) -> a -> b
$       -- Do *not* use bindLocalNameFV here
                                        -- See Note [View pattern usage]
             MiniFixityEnv -> [Name] -> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a. MiniFixityEnv -> [Name] -> RnM a -> RnM a
addLocalFixities MiniFixityEnv
fix_env [Name
name] (RnM (r, FreeVars) -> RnM (r, FreeVars))
-> RnM (r, FreeVars) -> RnM (r, FreeVars)
forall a b. (a -> b) -> a -> b
$
             Name -> RnM (r, FreeVars)
thing_inside Name
name })

    -- Note: the bindLocalNames is somewhat suspicious
    --       because it binds a top-level name as a local name.
    --       however, this binding seems to work, and it only exists for
    --       the duration of the patterns and the continuation;
    --       then the top-level name is added to the global env
    --       before going on to the RHSes (see RnSource.hs).

{-
Note [View pattern usage]
~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
  let (r, (r -> x)) = x in ...
Here the pattern binds 'r', and then uses it *only* in the view pattern.
We want to "see" this use, and in let-bindings we collect all uses and
report unused variables at the binding level. So we must use bindLocalNames
here, *not* bindLocalNameFV.  Trac #3943.


Note [Don't report shadowing for pattern synonyms]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is one special context where a pattern doesn't introduce any new binders -
pattern synonym declarations. Therefore we don't check to see if pattern
variables shadow existing identifiers as they are never bound to anything
and have no scope.

Without this check, there would be quite a cryptic warning that the `x`
in the RHS of the pattern synonym declaration shadowed the top level `x`.

```
x :: ()
x = ()

pattern P x = Just x
```

See #12615 for some more examples.

*********************************************************
*                                                      *
        External entry points
*                                                      *
*********************************************************

There are various entry points to renaming patterns, depending on
 (1) whether the names created should be top-level names or local names
 (2) whether the scope of the names is entirely given in a continuation
     (e.g., in a case or lambda, but not in a let or at the top-level,
      because of the way mutually recursive bindings are handled)
 (3) whether the a type signature in the pattern can bind
        lexically-scoped type variables (for unpacking existential
        type vars in data constructors)
 (4) whether we do duplicate and unused variable checking
 (5) whether there are fixity declarations associated with the names
     bound by the patterns that need to be brought into scope with them.

 Rather than burdening the clients of this module with all of these choices,
 we export the three points in this design space that we actually need:
-}

-- ----------- Entry point 1: rnPats -------------------
-- Binds local names; the scope of the bindings is entirely in the thing_inside
--   * allows type sigs to bind type vars
--   * local namemaker
--   * unused and duplicate checking
--   * no fixities
rnPats :: HsMatchContext Name -- for error messages
       -> [LPat GhcPs]
       -> ([LPat GhcRn] -> RnM (a, FreeVars))
       -> RnM (a, FreeVars)
rnPats :: HsMatchContext Name
-> [LPat GhcPs]
-> ([LPat GhcRn] -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
rnPats ctxt :: HsMatchContext Name
ctxt pats :: [LPat GhcPs]
pats thing_inside :: [LPat GhcRn] -> RnM (a, FreeVars)
thing_inside
  = do  { (GlobalRdrEnv, LocalRdrEnv)
envs_before <- TcRn (GlobalRdrEnv, LocalRdrEnv)
getRdrEnvs

          -- (1) rename the patterns, bringing into scope all of the term variables
          -- (2) then do the thing inside.
        ; CpsRn [LPat GhcRn]
-> forall r.
   ([LPat GhcRn] -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
forall b.
CpsRn b -> forall r. (b -> RnM (r, FreeVars)) -> RnM (r, FreeVars)
unCpsRn (NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen (HsMatchContext Name -> NameMaker
forall a. HsMatchContext a -> NameMaker
matchNameMaker HsMatchContext Name
ctxt) [LPat GhcPs]
pats) (([LPat GhcRn] -> RnM (a, FreeVars)) -> RnM (a, FreeVars))
-> ([LPat GhcRn] -> RnM (a, FreeVars)) -> RnM (a, FreeVars)
forall a b. (a -> b) -> a -> b
$ \ pats' :: [LPat GhcRn]
pats' -> do
        { -- Check for duplicated and shadowed names
          -- Must do this *after* renaming the patterns
          -- See Note [Collect binders only after renaming] in HsUtils
          -- Because we don't bind the vars all at once, we can't
          --    check incrementally for duplicates;
          -- Nor can we check incrementally for shadowing, else we'll
          --    complain *twice* about duplicates e.g. f (x,x) = ...
          --
          -- See note [Don't report shadowing for pattern synonyms]
        ; let bndrs :: [IdP GhcRn]
bndrs = [LPat GhcRn] -> [IdP GhcRn]
forall (p :: Pass). [LPat (GhcPass p)] -> [IdP (GhcPass p)]
collectPatsBinders [LPat GhcRn]
pats'
        ; MsgDoc
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt MsgDoc
doc_pat (IOEnv (Env TcGblEnv TcLclEnv) ()
 -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
          if HsMatchContext Name -> Bool
forall id. HsMatchContext id -> Bool
isPatSynCtxt HsMatchContext Name
ctxt
             then [Name] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupNames [Name]
[IdP GhcRn]
bndrs
             else (GlobalRdrEnv, LocalRdrEnv)
-> [Name] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupAndShadowedNames (GlobalRdrEnv, LocalRdrEnv)
envs_before [Name]
[IdP GhcRn]
bndrs
        ; [LPat GhcRn] -> RnM (a, FreeVars)
thing_inside [LPat GhcRn]
pats' } }
  where
    doc_pat :: MsgDoc
doc_pat = String -> MsgDoc
text "In" MsgDoc -> MsgDoc -> MsgDoc
<+> HsMatchContext Name -> MsgDoc
forall id.
(Outputable (NameOrRdrName id), Outputable id) =>
HsMatchContext id -> MsgDoc
pprMatchContext HsMatchContext Name
ctxt

rnPat :: HsMatchContext Name -- for error messages
      -> LPat GhcPs
      -> (LPat GhcRn -> RnM (a, FreeVars))
      -> RnM (a, FreeVars)     -- Variables bound by pattern do not
                               -- appear in the result FreeVars
rnPat :: HsMatchContext Name
-> LPat GhcPs
-> (LPat GhcRn -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
rnPat ctxt :: HsMatchContext Name
ctxt pat :: LPat GhcPs
pat thing_inside :: LPat GhcRn -> RnM (a, FreeVars)
thing_inside
  = HsMatchContext Name
-> [LPat GhcPs]
-> ([LPat GhcRn] -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
forall a.
HsMatchContext Name
-> [LPat GhcPs]
-> ([LPat GhcRn] -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
rnPats HsMatchContext Name
ctxt [LPat GhcPs
pat] (\pats' :: [LPat GhcRn]
pats' -> let [pat' :: LPat GhcRn
pat'] = [LPat GhcRn]
pats' in LPat GhcRn -> RnM (a, FreeVars)
thing_inside LPat GhcRn
pat')

applyNameMaker :: NameMaker -> Located RdrName -> RnM (Located Name)
applyNameMaker :: NameMaker -> Located RdrName -> RnM (Located Name)
applyNameMaker mk :: NameMaker
mk rdr :: Located RdrName
rdr = do { (n :: Located Name
n, _fvs :: FreeVars
_fvs) <- CpsRn (Located Name) -> RnM (Located Name, FreeVars)
forall a. CpsRn a -> RnM (a, FreeVars)
runCps (NameMaker -> Located RdrName -> CpsRn (Located Name)
newPatLName NameMaker
mk Located RdrName
rdr)
                           ; Located Name -> RnM (Located Name)
forall (m :: * -> *) a. Monad m => a -> m a
return Located Name
n }

-- ----------- Entry point 2: rnBindPat -------------------
-- Binds local names; in a recursive scope that involves other bound vars
--      e.g let { (x, Just y) = e1; ... } in ...
--   * does NOT allows type sig to bind type vars
--   * local namemaker
--   * no unused and duplicate checking
--   * fixities might be coming in
rnBindPat :: NameMaker
          -> LPat GhcPs
          -> RnM (LPat GhcRn, FreeVars)
   -- Returned FreeVars are the free variables of the pattern,
   -- of course excluding variables bound by this pattern

rnBindPat :: NameMaker -> LPat GhcPs -> RnM (LPat GhcRn, FreeVars)
rnBindPat name_maker :: NameMaker
name_maker pat :: LPat GhcPs
pat = CpsRn (LPat GhcRn) -> RnM (LPat GhcRn, FreeVars)
forall a. CpsRn a -> RnM (a, FreeVars)
runCps (NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
name_maker LPat GhcPs
pat)

{-
*********************************************************
*                                                      *
        The main event
*                                                      *
*********************************************************
-}

-- ----------- Entry point 3: rnLPatAndThen -------------------
-- General version: parametrized by how you make new names

rnLPatsAndThen :: NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen :: NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen mk :: NameMaker
mk = (LPat GhcPs -> CpsRn (LPat GhcRn))
-> [LPat GhcPs] -> CpsRn [LPat GhcRn]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk)
  -- Despite the map, the monad ensures that each pattern binds
  -- variables that may be mentioned in subsequent patterns in the list

--------------------
-- The workhorse
rnLPatAndThen :: NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen :: NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen nm :: NameMaker
nm lpat :: LPat GhcPs
lpat = (SrcSpanLess (LPat GhcPs) -> CpsRn (SrcSpanLess (LPat GhcRn)))
-> LPat GhcPs -> CpsRn (LPat GhcRn)
forall a b.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> CpsRn (SrcSpanLess b)) -> a -> CpsRn b
wrapSrcSpanCps (NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen NameMaker
nm) LPat GhcPs
lpat

rnPatAndThen :: NameMaker -> Pat GhcPs -> CpsRn (Pat GhcRn)
rnPatAndThen :: NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen _  (WildPat _)   = LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XWildPat GhcRn -> LPat GhcRn
forall p. XWildPat p -> Pat p
WildPat XWildPat GhcRn
NoExt
noExt)
rnPatAndThen mk :: NameMaker
mk (ParPat x :: XParPat GhcPs
x pat :: LPat GhcPs
pat)  = do { LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
                                     ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XParPat GhcRn -> LPat GhcRn -> LPat GhcRn
forall p. XParPat p -> Pat p -> Pat p
ParPat XParPat GhcPs
XParPat GhcRn
x LPat GhcRn
pat') }
rnPatAndThen mk :: NameMaker
mk (LazyPat x :: XLazyPat GhcPs
x pat :: LPat GhcPs
pat) = do { LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
                                     ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLazyPat GhcRn -> LPat GhcRn -> LPat GhcRn
forall p. XLazyPat p -> Pat p -> Pat p
LazyPat XLazyPat GhcPs
XLazyPat GhcRn
x LPat GhcRn
pat') }
rnPatAndThen mk :: NameMaker
mk (BangPat x :: XBangPat GhcPs
x pat :: LPat GhcPs
pat) = do { LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
                                     ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XBangPat GhcRn -> LPat GhcRn -> LPat GhcRn
forall p. XBangPat p -> Pat p -> Pat p
BangPat XBangPat GhcPs
XBangPat GhcRn
x LPat GhcRn
pat') }
rnPatAndThen mk :: NameMaker
mk (VarPat x :: XVarPat GhcPs
x (Located (IdP GhcPs) -> Located (SrcSpanLess (Located RdrName))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l rdr :: SrcSpanLess (Located RdrName)
rdr))
    = do { SrcSpan
loc <- RnM SrcSpan -> CpsRn SrcSpan
forall a. RnM a -> CpsRn a
liftCps RnM SrcSpan
getSrcSpanM
         ; Name
name <- NameMaker -> Located RdrName -> CpsRn Name
newPatName NameMaker
mk (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
rdr)
         ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XVarPat GhcRn -> Located (IdP GhcRn) -> LPat GhcRn
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcPs
XVarPat GhcRn
x (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l Name
SrcSpanLess (Located Name)
name)) }
     -- we need to bind pattern variables for view pattern expressions
     -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple)

rnPatAndThen mk :: NameMaker
mk (SigPat x :: XSigPat GhcPs
x pat :: LPat GhcPs
pat sig :: LHsSigWcType (NoGhcTc GhcPs)
sig)
  -- When renaming a pattern type signature (e.g. f (a :: T) = ...), it is
  -- important to rename its type signature _before_ renaming the rest of the
  -- pattern, so that type variables are first bound by the _outermost_ pattern
  -- type signature they occur in. This keeps the type checker happy when
  -- pattern type signatures happen to be nested (#7827)
  --
  -- f ((Just (x :: a) :: Maybe a)
  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~^       `a' is first bound here
  -- ~~~~~~~~~~~~~~~^                   the same `a' then used here
  = do { LHsSigWcType GhcRn
sig' <- LHsSigWcType GhcPs -> CpsRn (LHsSigWcType GhcRn)
rnHsSigCps LHsSigWcType (NoGhcTc GhcPs)
LHsSigWcType GhcPs
sig
       ; LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSigPat GhcRn
-> LPat GhcRn -> LHsSigWcType (NoGhcTc GhcRn) -> LPat GhcRn
forall p. XSigPat p -> Pat p -> LHsSigWcType (NoGhcTc p) -> Pat p
SigPat XSigPat GhcPs
XSigPat GhcRn
x LPat GhcRn
pat' LHsSigWcType (NoGhcTc GhcRn)
LHsSigWcType GhcRn
sig' ) }

rnPatAndThen mk :: NameMaker
mk (LitPat x :: XLitPat GhcPs
x lit :: HsLit GhcPs
lit)
  | HsString src :: XHsString GhcPs
src s :: FastString
s <- HsLit GhcPs
lit
  = do { Bool
ovlStr <- RnM Bool -> CpsRn Bool
forall a. RnM a -> CpsRn a
liftCps (Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.OverloadedStrings)
       ; if Bool
ovlStr
         then NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen NameMaker
mk
                           (Located (HsOverLit GhcPs) -> Maybe (SyntaxExpr GhcPs) -> LPat GhcPs
mkNPat (SrcSpanLess (Located (HsOverLit GhcPs))
-> Located (HsOverLit GhcPs)
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (SourceText -> FastString -> HsOverLit GhcPs
mkHsIsString SourceText
XHsString GhcPs
src FastString
s))
                                      Maybe (SyntaxExpr GhcPs)
forall a. Maybe a
Nothing)
         else CpsRn (LPat GhcRn)
normal_lit }
  | Bool
otherwise = CpsRn (LPat GhcRn)
normal_lit
  where
    normal_lit :: CpsRn (LPat GhcRn)
normal_lit = do { IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ()
forall a. RnM a -> CpsRn a
liftCps (HsLit GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall p. HsLit p -> IOEnv (Env TcGblEnv TcLclEnv) ()
rnLit HsLit GhcPs
lit); LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLitPat GhcRn -> HsLit GhcRn -> LPat GhcRn
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcPs
XLitPat GhcRn
x (HsLit GhcPs -> HsLit GhcRn
forall a b. ConvertIdX a b => HsLit a -> HsLit b
convertLit HsLit GhcPs
lit)) }

rnPatAndThen _ (NPat x :: XNPat GhcPs
x (Located (HsOverLit GhcPs)
-> Located (SrcSpanLess (Located (HsOverLit GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l lit :: SrcSpanLess (Located (HsOverLit GhcPs))
lit) mb_neg :: Maybe (SyntaxExpr GhcPs)
mb_neg _eq :: SyntaxExpr GhcPs
_eq)
  = do { (lit' :: HsOverLit GhcRn
lit', mb_neg' :: Maybe (HsExpr GhcRn)
mb_neg') <- RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn))
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
 -> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn)))
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn))
forall a b. (a -> b) -> a -> b
$ HsOverLit GhcPs
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
forall t.
HsOverLit t
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
rnOverLit SrcSpanLess (Located (HsOverLit GhcPs))
HsOverLit GhcPs
lit
       ; Maybe (SyntaxExpr GhcRn)
mb_neg' -- See Note [Negative zero]
           <- let negative :: IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
negative = do { (neg :: SyntaxExpr GhcRn
neg, fvs :: FreeVars
fvs) <- Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
negateName
                                ; (Maybe (SyntaxExpr GhcRn), FreeVars)
-> IOEnv
     (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (SyntaxExpr GhcRn -> Maybe (SyntaxExpr GhcRn)
forall a. a -> Maybe a
Just SyntaxExpr GhcRn
neg, FreeVars
fvs) }
                  positive :: IOEnv (Env TcGblEnv TcLclEnv) (Maybe a, FreeVars)
positive = (Maybe a, FreeVars)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe a, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a
forall a. Maybe a
Nothing, FreeVars
emptyFVs)
              in IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
-> CpsRn (Maybe (SyntaxExpr GhcRn))
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
 -> CpsRn (Maybe (SyntaxExpr GhcRn)))
-> IOEnv
     (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
-> CpsRn (Maybe (SyntaxExpr GhcRn))
forall a b. (a -> b) -> a -> b
$ case (Maybe (SyntaxExpr GhcPs)
mb_neg , Maybe (HsExpr GhcRn)
mb_neg') of
                                  (Nothing, Just _ ) -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
negative
                                  (Just _ , Nothing) -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
negative
                                  (Nothing, Nothing) -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
forall a. IOEnv (Env TcGblEnv TcLclEnv) (Maybe a, FreeVars)
positive
                                  (Just _ , Just _ ) -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (SyntaxExpr GhcRn), FreeVars)
forall a. IOEnv (Env TcGblEnv TcLclEnv) (Maybe a, FreeVars)
positive
       ; SyntaxExpr GhcRn
eq' <- RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn))
-> RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a b. (a -> b) -> a -> b
$ Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
eqName
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XNPat GhcRn
-> Located (HsOverLit GhcRn)
-> Maybe (SyntaxExpr GhcRn)
-> SyntaxExpr GhcRn
-> LPat GhcRn
forall p.
XNPat p
-> Located (HsOverLit p)
-> Maybe (SyntaxExpr p)
-> SyntaxExpr p
-> Pat p
NPat XNPat GhcPs
XNPat GhcRn
x (SrcSpan
-> SrcSpanLess (Located (HsOverLit GhcRn))
-> Located (HsOverLit GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
lit') Maybe (SyntaxExpr GhcRn)
mb_neg' SyntaxExpr GhcRn
eq') }

rnPatAndThen mk :: NameMaker
mk (NPlusKPat x :: XNPlusKPat GhcPs
x rdr :: Located (IdP GhcPs)
rdr (Located (HsOverLit GhcPs)
-> Located (SrcSpanLess (Located (HsOverLit GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l lit :: SrcSpanLess (Located (HsOverLit GhcPs))
lit) _ _ _ )
  = do { Name
new_name <- NameMaker -> Located RdrName -> CpsRn Name
newPatName NameMaker
mk Located RdrName
Located (IdP GhcPs)
rdr
       ; (lit' :: HsOverLit GhcRn
lit', _) <- RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn))
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
 -> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn)))
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> CpsRn (HsOverLit GhcRn, Maybe (HsExpr GhcRn))
forall a b. (a -> b) -> a -> b
$ HsOverLit GhcPs
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
forall t.
HsOverLit t
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
rnOverLit SrcSpanLess (Located (HsOverLit GhcPs))
HsOverLit GhcPs
lit -- See Note [Negative zero]
                                                -- We skip negateName as
                                                -- negative zero doesn't make
                                                -- sense in n + k patterns
       ; SyntaxExpr GhcRn
minus <- RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn))
-> RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a b. (a -> b) -> a -> b
$ Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
minusName
       ; SyntaxExpr GhcRn
ge    <- RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn))
-> RnM (SyntaxExpr GhcRn, FreeVars) -> CpsRn (SyntaxExpr GhcRn)
forall a b. (a -> b) -> a -> b
$ Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
geName
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XNPlusKPat GhcRn
-> Located (IdP GhcRn)
-> Located (HsOverLit GhcRn)
-> HsOverLit GhcRn
-> SyntaxExpr GhcRn
-> SyntaxExpr GhcRn
-> LPat GhcRn
forall p.
XNPlusKPat p
-> Located (IdP p)
-> Located (HsOverLit p)
-> HsOverLit p
-> SyntaxExpr p
-> SyntaxExpr p
-> Pat p
NPlusKPat XNPlusKPat GhcPs
XNPlusKPat GhcRn
x (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL (Name -> SrcSpan
nameSrcSpan Name
new_name) Name
SrcSpanLess (Located Name)
new_name)
                             (SrcSpan
-> SrcSpanLess (Located (HsOverLit GhcRn))
-> Located (HsOverLit GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l SrcSpanLess (Located (HsOverLit GhcRn))
HsOverLit GhcRn
lit') HsOverLit GhcRn
lit' SyntaxExpr GhcRn
ge SyntaxExpr GhcRn
minus) }
                -- The Report says that n+k patterns must be in Integral

rnPatAndThen mk :: NameMaker
mk (AsPat x :: XAsPat GhcPs
x rdr :: Located (IdP GhcPs)
rdr pat :: LPat GhcPs
pat)
  = do { Located Name
new_name <- NameMaker -> Located RdrName -> CpsRn (Located Name)
newPatLName NameMaker
mk Located RdrName
Located (IdP GhcPs)
rdr
       ; LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XAsPat GhcRn -> Located (IdP GhcRn) -> LPat GhcRn -> LPat GhcRn
forall p. XAsPat p -> Located (IdP p) -> Pat p -> Pat p
AsPat XAsPat GhcPs
XAsPat GhcRn
x Located Name
Located (IdP GhcRn)
new_name LPat GhcRn
pat') }

rnPatAndThen mk :: NameMaker
mk p :: LPat GhcPs
p@(ViewPat x :: XViewPat GhcPs
x expr :: LHsExpr GhcPs
expr pat :: LPat GhcPs
pat)
  = do { IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ()
forall a. RnM a -> CpsRn a
liftCps (IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ())
-> IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ()
forall a b. (a -> b) -> a -> b
$ do { Bool
vp_flag <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.ViewPatterns
                      ; Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkErr Bool
vp_flag (LPat GhcPs -> MsgDoc
badViewPat LPat GhcPs
p) }
         -- Because of the way we're arranging the recursive calls,
         -- this will be in the right context
       ; LHsExpr GhcRn
expr' <- RnM (LHsExpr GhcRn, FreeVars) -> CpsRn (LHsExpr GhcRn)
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM (LHsExpr GhcRn, FreeVars) -> CpsRn (LHsExpr GhcRn))
-> RnM (LHsExpr GhcRn, FreeVars) -> CpsRn (LHsExpr GhcRn)
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> RnM (LHsExpr GhcRn, FreeVars)
rnLExpr LHsExpr GhcPs
expr
       ; LPat GhcRn
pat' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
       -- Note: at this point the PreTcType in ty can only be a placeHolder
       -- ; return (ViewPat expr' pat' ty) }
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XViewPat GhcRn -> LHsExpr GhcRn -> LPat GhcRn -> LPat GhcRn
forall p. XViewPat p -> LHsExpr p -> Pat p -> Pat p
ViewPat XViewPat GhcPs
XViewPat GhcRn
x LHsExpr GhcRn
expr' LPat GhcRn
pat') }

rnPatAndThen mk :: NameMaker
mk (ConPatIn con :: Located (IdP GhcPs)
con stuff :: HsConPatDetails GhcPs
stuff)
   -- rnConPatAndThen takes care of reconstructing the pattern
   -- The pattern for the empty list needs to be replaced by an empty explicit list pattern when overloaded lists is turned on.
  = case Located RdrName -> SrcSpanLess (Located RdrName)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located RdrName
Located (IdP GhcPs)
con RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== Name -> RdrName
nameRdrName (DataCon -> Name
dataConName DataCon
nilDataCon) of
      True    -> do { Bool
ol_flag <- RnM Bool -> CpsRn Bool
forall a. RnM a -> CpsRn a
liftCps (RnM Bool -> CpsRn Bool) -> RnM Bool -> CpsRn Bool
forall a b. (a -> b) -> a -> b
$ Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.OverloadedLists
                    ; if Bool
ol_flag then NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen NameMaker
mk (XListPat GhcPs -> [LPat GhcPs] -> LPat GhcPs
forall p. XListPat p -> [Pat p] -> Pat p
ListPat XListPat GhcPs
NoExt
noExt [])
                                 else NameMaker
-> Located RdrName -> HsConPatDetails GhcPs -> CpsRn (LPat GhcRn)
rnConPatAndThen NameMaker
mk Located RdrName
Located (IdP GhcPs)
con HsConPatDetails GhcPs
stuff}
      False   -> NameMaker
-> Located RdrName -> HsConPatDetails GhcPs -> CpsRn (LPat GhcRn)
rnConPatAndThen NameMaker
mk Located RdrName
Located (IdP GhcPs)
con HsConPatDetails GhcPs
stuff

rnPatAndThen mk :: NameMaker
mk (ListPat _ pats :: [LPat GhcPs]
pats)
  = do { Bool
opt_OverloadedLists <- RnM Bool -> CpsRn Bool
forall a. RnM a -> CpsRn a
liftCps (RnM Bool -> CpsRn Bool) -> RnM Bool -> CpsRn Bool
forall a b. (a -> b) -> a -> b
$ Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.OverloadedLists
       ; [LPat GhcRn]
pats' <- NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen NameMaker
mk [LPat GhcPs]
pats
       ; case Bool
opt_OverloadedLists of
          True -> do { (to_list_name :: SyntaxExpr GhcRn
to_list_name,_) <- RnM (SyntaxExpr GhcRn, FreeVars)
-> CpsRn (SyntaxExpr GhcRn, FreeVars)
forall a. RnM a -> CpsRn a
liftCps (RnM (SyntaxExpr GhcRn, FreeVars)
 -> CpsRn (SyntaxExpr GhcRn, FreeVars))
-> RnM (SyntaxExpr GhcRn, FreeVars)
-> CpsRn (SyntaxExpr GhcRn, FreeVars)
forall a b. (a -> b) -> a -> b
$ Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
toListName
                     ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XListPat GhcRn -> [LPat GhcRn] -> LPat GhcRn
forall p. XListPat p -> [Pat p] -> Pat p
ListPat (SyntaxExpr GhcRn -> Maybe (SyntaxExpr GhcRn)
forall a. a -> Maybe a
Just SyntaxExpr GhcRn
to_list_name) [LPat GhcRn]
pats')}
          False -> LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XListPat GhcRn -> [LPat GhcRn] -> LPat GhcRn
forall p. XListPat p -> [Pat p] -> Pat p
ListPat XListPat GhcRn
forall a. Maybe a
Nothing [LPat GhcRn]
pats') }

rnPatAndThen mk :: NameMaker
mk (TuplePat x :: XTuplePat GhcPs
x pats :: [LPat GhcPs]
pats boxed :: Boxity
boxed)
  = do { IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ()
forall a. RnM a -> CpsRn a
liftCps (IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ())
-> IOEnv (Env TcGblEnv TcLclEnv) () -> CpsRn ()
forall a b. (a -> b) -> a -> b
$ Int -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTupSize ([LPat GhcPs] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcPs]
pats)
       ; [LPat GhcRn]
pats' <- NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen NameMaker
mk [LPat GhcPs]
pats
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTuplePat GhcRn -> [LPat GhcRn] -> Boxity -> LPat GhcRn
forall p. XTuplePat p -> [Pat p] -> Boxity -> Pat p
TuplePat XTuplePat GhcPs
XTuplePat GhcRn
x [LPat GhcRn]
pats' Boxity
boxed) }

rnPatAndThen mk :: NameMaker
mk (SumPat x :: XSumPat GhcPs
x pat :: LPat GhcPs
pat alt :: Int
alt arity :: Int
arity)
  = do { LPat GhcRn
pat <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat
       ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSumPat GhcRn -> LPat GhcRn -> Int -> Int -> LPat GhcRn
forall p. XSumPat p -> Pat p -> Int -> Int -> Pat p
SumPat XSumPat GhcPs
XSumPat GhcRn
x LPat GhcRn
pat Int
alt Int
arity)
       }

-- If a splice has been run already, just rename the result.
rnPatAndThen mk :: NameMaker
mk (SplicePat x :: XSplicePat GhcPs
x (HsSpliced x2 :: XSpliced GhcPs
x2 mfs :: ThModFinalizers
mfs (HsSplicedPat pat :: LPat GhcPs
pat)))
  = XSplicePat GhcRn -> HsSplice GhcRn -> LPat GhcRn
forall p. XSplicePat p -> HsSplice p -> Pat p
SplicePat XSplicePat GhcPs
XSplicePat GhcRn
x (HsSplice GhcRn -> LPat GhcRn)
-> (LPat GhcRn -> HsSplice GhcRn) -> LPat GhcRn -> LPat GhcRn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSpliced GhcRn
-> ThModFinalizers -> HsSplicedThing GhcRn -> HsSplice GhcRn
forall id.
XSpliced id -> ThModFinalizers -> HsSplicedThing id -> HsSplice id
HsSpliced XSpliced GhcPs
XSpliced GhcRn
x2 ThModFinalizers
mfs (HsSplicedThing GhcRn -> HsSplice GhcRn)
-> (LPat GhcRn -> HsSplicedThing GhcRn)
-> LPat GhcRn
-> HsSplice GhcRn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LPat GhcRn -> HsSplicedThing GhcRn
forall id. Pat id -> HsSplicedThing id
HsSplicedPat (LPat GhcRn -> LPat GhcRn)
-> CpsRn (LPat GhcRn) -> CpsRn (LPat GhcRn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen NameMaker
mk LPat GhcPs
pat

rnPatAndThen mk :: NameMaker
mk (SplicePat _ splice :: HsSplice GhcPs
splice)
  = do { Either (LPat GhcPs) (LPat GhcRn)
eith <- RnM (Either (LPat GhcPs) (LPat GhcRn), FreeVars)
-> CpsRn (Either (LPat GhcPs) (LPat GhcRn))
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM (Either (LPat GhcPs) (LPat GhcRn), FreeVars)
 -> CpsRn (Either (LPat GhcPs) (LPat GhcRn)))
-> RnM (Either (LPat GhcPs) (LPat GhcRn), FreeVars)
-> CpsRn (Either (LPat GhcPs) (LPat GhcRn))
forall a b. (a -> b) -> a -> b
$ HsSplice GhcPs -> RnM (Either (LPat GhcPs) (LPat GhcRn), FreeVars)
rnSplicePat HsSplice GhcPs
splice
       ; case Either (LPat GhcPs) (LPat GhcRn)
eith of   -- See Note [rnSplicePat] in RnSplice
           Left  not_yet_renamed :: LPat GhcPs
not_yet_renamed -> NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnPatAndThen NameMaker
mk LPat GhcPs
not_yet_renamed
           Right already_renamed :: LPat GhcRn
already_renamed -> LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return LPat GhcRn
already_renamed }

rnPatAndThen _ pat :: LPat GhcPs
pat = String -> MsgDoc -> CpsRn (LPat GhcRn)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnLPatAndThen" (LPat GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr LPat GhcPs
pat)


--------------------
rnConPatAndThen :: NameMaker
                -> Located RdrName    -- the constructor
                -> HsConPatDetails GhcPs
                -> CpsRn (Pat GhcRn)

rnConPatAndThen :: NameMaker
-> Located RdrName -> HsConPatDetails GhcPs -> CpsRn (LPat GhcRn)
rnConPatAndThen mk :: NameMaker
mk con :: Located RdrName
con (PrefixCon pats :: [LPat GhcPs]
pats)
  = do  { Located Name
con' <- Located RdrName -> CpsRn (Located Name)
lookupConCps Located RdrName
con
        ; [LPat GhcRn]
pats' <- NameMaker -> [LPat GhcPs] -> CpsRn [LPat GhcRn]
rnLPatsAndThen NameMaker
mk [LPat GhcPs]
pats
        ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (Located (IdP GhcRn) -> HsConPatDetails GhcRn -> LPat GhcRn
forall p. Located (IdP p) -> HsConPatDetails p -> Pat p
ConPatIn Located Name
Located (IdP GhcRn)
con' ([LPat GhcRn] -> HsConPatDetails GhcRn
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon [LPat GhcRn]
pats')) }

rnConPatAndThen mk :: NameMaker
mk con :: Located RdrName
con (InfixCon pat1 :: LPat GhcPs
pat1 pat2 :: LPat GhcPs
pat2)
  = do  { Located Name
con' <- Located RdrName -> CpsRn (Located Name)
lookupConCps Located RdrName
con
        ; LPat GhcRn
pat1' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat1
        ; LPat GhcRn
pat2' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen NameMaker
mk LPat GhcPs
pat2
        ; Fixity
fixity <- RnM Fixity -> CpsRn Fixity
forall a. RnM a -> CpsRn a
liftCps (RnM Fixity -> CpsRn Fixity) -> RnM Fixity -> CpsRn Fixity
forall a b. (a -> b) -> a -> b
$ Name -> RnM Fixity
lookupFixityRn (Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
con')
        ; RnM (LPat GhcRn) -> CpsRn (LPat GhcRn)
forall a. RnM a -> CpsRn a
liftCps (RnM (LPat GhcRn) -> CpsRn (LPat GhcRn))
-> RnM (LPat GhcRn) -> CpsRn (LPat GhcRn)
forall a b. (a -> b) -> a -> b
$ Located Name
-> Fixity -> LPat GhcRn -> LPat GhcRn -> RnM (LPat GhcRn)
mkConOpPatRn Located Name
con' Fixity
fixity LPat GhcRn
pat1' LPat GhcRn
pat2' }

rnConPatAndThen mk :: NameMaker
mk con :: Located RdrName
con (RecCon rpats :: HsRecFields GhcPs (LPat GhcPs)
rpats)
  = do  { Located Name
con' <- Located RdrName -> CpsRn (Located Name)
lookupConCps Located RdrName
con
        ; HsRecFields GhcRn (LPat GhcRn)
rpats' <- NameMaker
-> Located Name
-> HsRecFields GhcPs (LPat GhcPs)
-> CpsRn (HsRecFields GhcRn (LPat GhcRn))
rnHsRecPatsAndThen NameMaker
mk Located Name
con' HsRecFields GhcPs (LPat GhcPs)
rpats
        ; LPat GhcRn -> CpsRn (LPat GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (Located (IdP GhcRn) -> HsConPatDetails GhcRn -> LPat GhcRn
forall p. Located (IdP p) -> HsConPatDetails p -> Pat p
ConPatIn Located Name
Located (IdP GhcRn)
con' (HsRecFields GhcRn (LPat GhcRn) -> HsConPatDetails GhcRn
forall arg rec. rec -> HsConDetails arg rec
RecCon HsRecFields GhcRn (LPat GhcRn)
rpats')) }

--------------------
rnHsRecPatsAndThen :: NameMaker
                   -> Located Name      -- Constructor
                   -> HsRecFields GhcPs (LPat GhcPs)
                   -> CpsRn (HsRecFields GhcRn (LPat GhcRn))
rnHsRecPatsAndThen :: NameMaker
-> Located Name
-> HsRecFields GhcPs (LPat GhcPs)
-> CpsRn (HsRecFields GhcRn (LPat GhcRn))
rnHsRecPatsAndThen mk :: NameMaker
mk (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ con :: SrcSpanLess (Located Name)
con)
     hs_rec_fields :: HsRecFields GhcPs (LPat GhcPs)
hs_rec_fields@(HsRecFields { rec_dotdot :: forall p arg. HsRecFields p arg -> Maybe Int
rec_dotdot = Maybe Int
dd })
  = do { [LHsRecField GhcRn (LPat GhcPs)]
flds <- RnM ([LHsRecField GhcRn (LPat GhcPs)], FreeVars)
-> CpsRn [LHsRecField GhcRn (LPat GhcPs)]
forall a. RnM (a, FreeVars) -> CpsRn a
liftCpsFV (RnM ([LHsRecField GhcRn (LPat GhcPs)], FreeVars)
 -> CpsRn [LHsRecField GhcRn (LPat GhcPs)])
-> RnM ([LHsRecField GhcRn (LPat GhcPs)], FreeVars)
-> CpsRn [LHsRecField GhcRn (LPat GhcPs)]
forall a b. (a -> b) -> a -> b
$ HsRecFieldContext
-> (SrcSpan -> RdrName -> SrcSpanLess (LPat GhcPs))
-> HsRecFields GhcPs (LPat GhcPs)
-> RnM ([LHsRecField GhcRn (LPat GhcPs)], FreeVars)
forall arg.
HasSrcSpan arg =>
HsRecFieldContext
-> (SrcSpan -> RdrName -> SrcSpanLess arg)
-> HsRecFields GhcPs arg
-> RnM ([LHsRecField GhcRn arg], FreeVars)
rnHsRecFields (Name -> HsRecFieldContext
HsRecFieldPat Name
SrcSpanLess (Located Name)
con) SrcSpan -> RdrName -> SrcSpanLess (LPat GhcPs)
forall p. (XVarPat p ~ NoExt) => SrcSpan -> IdP p -> Pat p
mkVarPat
                                            HsRecFields GhcPs (LPat GhcPs)
hs_rec_fields
       ; [LHsRecField GhcRn (LPat GhcRn)]
flds' <- ((LHsRecField GhcRn (LPat GhcPs), Int)
 -> CpsRn (LHsRecField GhcRn (LPat GhcRn)))
-> [(LHsRecField GhcRn (LPat GhcPs), Int)]
-> CpsRn [LHsRecField GhcRn (LPat GhcRn)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LHsRecField GhcRn (LPat GhcPs), Int)
-> CpsRn (LHsRecField GhcRn (LPat GhcRn))
rn_field ([LHsRecField GhcRn (LPat GhcPs)]
flds [LHsRecField GhcRn (LPat GhcPs)]
-> [Int] -> [(LHsRecField GhcRn (LPat GhcPs), Int)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [1..])
       ; HsRecFields GhcRn (LPat GhcRn)
-> CpsRn (HsRecFields GhcRn (LPat GhcRn))
forall (m :: * -> *) a. Monad m => a -> m a
return (HsRecFields :: forall p arg. [LHsRecField p arg] -> Maybe Int -> HsRecFields p arg
HsRecFields { rec_flds :: [LHsRecField GhcRn (LPat GhcRn)]
rec_flds = [LHsRecField GhcRn (LPat GhcRn)]
flds', rec_dotdot :: Maybe Int
rec_dotdot = Maybe Int
dd }) }
  where
    mkVarPat :: SrcSpan -> IdP p -> Pat p
mkVarPat l :: SrcSpan
l n :: IdP p
n = XVarPat p -> Located (IdP p) -> Pat p
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat p
NoExt
noExt (SrcSpan -> SrcSpanLess (Located (IdP p)) -> Located (IdP p)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l SrcSpanLess (Located (IdP p))
IdP p
n)
    rn_field :: (LHsRecField GhcRn (LPat GhcPs), Int)
-> CpsRn (LHsRecField GhcRn (LPat GhcRn))
rn_field (LHsRecField GhcRn (LPat GhcPs)
-> Located (SrcSpanLess (LHsRecField GhcRn (LPat GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l fld :: SrcSpanLess (LHsRecField GhcRn (LPat GhcPs))
fld, n' :: Int
n') =
      do { LPat GhcRn
arg' <- NameMaker -> LPat GhcPs -> CpsRn (LPat GhcRn)
rnLPatAndThen (Maybe Int -> NameMaker -> Int -> NameMaker
forall a. Ord a => Maybe a -> NameMaker -> a -> NameMaker
nested_mk Maybe Int
dd NameMaker
mk Int
n') (HsRecField' (FieldOcc GhcRn) (LPat GhcPs) -> LPat GhcPs
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg SrcSpanLess (LHsRecField GhcRn (LPat GhcPs))
HsRecField' (FieldOcc GhcRn) (LPat GhcPs)
fld)
         ; LHsRecField GhcRn (LPat GhcRn)
-> CpsRn (LHsRecField GhcRn (LPat GhcRn))
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> SrcSpanLess (LHsRecField GhcRn (LPat GhcRn))
-> LHsRecField GhcRn (LPat GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l (SrcSpanLess (LHsRecField GhcRn (LPat GhcPs))
HsRecField' (FieldOcc GhcRn) (LPat GhcPs)
fld { hsRecFieldArg :: LPat GhcRn
hsRecFieldArg = LPat GhcRn
arg' })) }

        -- Suppress unused-match reporting for fields introduced by ".."
    nested_mk :: Maybe a -> NameMaker -> a -> NameMaker
nested_mk Nothing  mk :: NameMaker
mk                    _  = NameMaker
mk
    nested_mk (Just _) mk :: NameMaker
mk@(LetMk {})         _  = NameMaker
mk
    nested_mk (Just n :: a
n) (LamMk report_unused :: Bool
report_unused) n' :: a
n' = Bool -> NameMaker
LamMk (Bool
report_unused Bool -> Bool -> Bool
&& (a
n' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
n))

{-
************************************************************************
*                                                                      *
        Record fields
*                                                                      *
************************************************************************
-}

data HsRecFieldContext
  = HsRecFieldCon Name
  | HsRecFieldPat Name
  | HsRecFieldUpd

rnHsRecFields
    :: forall arg. HasSrcSpan arg =>
       HsRecFieldContext
    -> (SrcSpan -> RdrName -> SrcSpanLess arg)
         -- When punning, use this to build a new field
    -> HsRecFields GhcPs arg
    -> RnM ([LHsRecField GhcRn arg], FreeVars)

-- This surprisingly complicated pass
--   a) looks up the field name (possibly using disambiguation)
--   b) fills in puns and dot-dot stuff
-- When we've finished, we've renamed the LHS, but not the RHS,
-- of each x=e binding
--
-- This is used for record construction and pattern-matching, but not updates.

rnHsRecFields :: HsRecFieldContext
-> (SrcSpan -> RdrName -> SrcSpanLess arg)
-> HsRecFields GhcPs arg
-> RnM ([LHsRecField GhcRn arg], FreeVars)
rnHsRecFields ctxt :: HsRecFieldContext
ctxt mk_arg :: SrcSpan -> RdrName -> SrcSpanLess arg
mk_arg (HsRecFields { rec_flds :: forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds = [LHsRecField GhcPs arg]
flds, rec_dotdot :: forall p arg. HsRecFields p arg -> Maybe Int
rec_dotdot = Maybe Int
dotdot })
  = do { Bool
pun_ok      <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.RecordPuns
       ; Bool
disambig_ok <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DisambiguateRecordFields
       ; let parent :: Maybe Name
parent = Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
disambig_ok Maybe () -> Maybe Name -> Maybe Name
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Name
mb_con
       ; [LHsRecField GhcRn arg]
flds1  <- (LHsRecField GhcPs arg
 -> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg))
-> [LHsRecField GhcPs arg]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsRecField GhcRn arg]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Bool
-> Maybe Name
-> LHsRecField GhcPs arg
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg)
rn_fld Bool
pun_ok Maybe Name
parent) [LHsRecField GhcPs arg]
flds
       ; (NonEmpty RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [NonEmpty RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> (NonEmpty RdrName -> MsgDoc)
-> NonEmpty RdrName
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecFieldContext -> NonEmpty RdrName -> MsgDoc
dupFieldErr HsRecFieldContext
ctxt) [NonEmpty RdrName]
dup_flds
       ; [LHsRecField GhcRn arg]
dotdot_flds <- Maybe Int
-> Maybe Name
-> [LHsRecField GhcRn arg]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsRecField GhcRn arg]
rn_dotdot Maybe Int
dotdot Maybe Name
mb_con [LHsRecField GhcRn arg]
flds1
       ; let all_flds :: [LHsRecField GhcRn arg]
all_flds | [LHsRecField GhcRn arg] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsRecField GhcRn arg]
dotdot_flds = [LHsRecField GhcRn arg]
flds1
                      | Bool
otherwise        = [LHsRecField GhcRn arg]
flds1 [LHsRecField GhcRn arg]
-> [LHsRecField GhcRn arg] -> [LHsRecField GhcRn arg]
forall a. [a] -> [a] -> [a]
++ [LHsRecField GhcRn arg]
dotdot_flds
       ; ([LHsRecField GhcRn arg], FreeVars)
-> RnM ([LHsRecField GhcRn arg], FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsRecField GhcRn arg]
all_flds, [Name] -> FreeVars
mkFVs ([LHsRecField GhcRn arg] -> [Name]
forall arg. [LHsRecField GhcRn arg] -> [Name]
getFieldIds [LHsRecField GhcRn arg]
all_flds)) }
  where
    mb_con :: Maybe Name
mb_con = case HsRecFieldContext
ctxt of
                HsRecFieldCon con :: Name
con  -> Name -> Maybe Name
forall a. a -> Maybe a
Just Name
con
                HsRecFieldPat con :: Name
con  -> Name -> Maybe Name
forall a. a -> Maybe a
Just Name
con
                _ {- update -}     -> Maybe Name
forall a. Maybe a
Nothing

    rn_fld :: Bool -> Maybe Name -> LHsRecField GhcPs arg
           -> RnM (LHsRecField GhcRn arg)
    rn_fld :: Bool
-> Maybe Name
-> LHsRecField GhcPs arg
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg)
rn_fld pun_ok :: Bool
pun_ok parent :: Maybe Name
parent (LHsRecField GhcPs arg
-> Located (SrcSpanLess (LHsRecField GhcPs arg))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l
                           (HsRecField
                              { hsRecFieldLbl =
                                  (dL->L loc (FieldOcc _ (dL->L ll lbl)))
                              , hsRecFieldArg = arg
                              , hsRecPun      = pun }))
      = do { Name
sel <- SrcSpan -> RnM Name -> RnM Name
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (RnM Name -> RnM Name) -> RnM Name -> RnM Name
forall a b. (a -> b) -> a -> b
$ Maybe Name -> RdrName -> RnM Name
lookupRecFieldOcc Maybe Name
parent SrcSpanLess (Located RdrName)
RdrName
lbl
           ; arg
arg' <- if Bool
pun
                     then do { Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkErr Bool
pun_ok (Located RdrName -> MsgDoc
badPun (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
lbl))
                               -- Discard any module qualifier (#11662)
                             ; let arg_rdr :: RdrName
arg_rdr = OccName -> RdrName
mkRdrUnqual (RdrName -> OccName
rdrNameOcc SrcSpanLess (Located RdrName)
RdrName
lbl)
                             ; arg -> IOEnv (Env TcGblEnv TcLclEnv) arg
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> SrcSpanLess arg -> arg
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (SrcSpan -> RdrName -> SrcSpanLess arg
mk_arg SrcSpan
loc RdrName
arg_rdr)) }
                     else arg -> IOEnv (Env TcGblEnv TcLclEnv) arg
forall (m :: * -> *) a. Monad m => a -> m a
return arg
arg
           ; LHsRecField GhcRn arg
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> SrcSpanLess (LHsRecField GhcRn arg) -> LHsRecField GhcRn arg
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l (HsRecField :: forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField
                             { hsRecFieldLbl :: Located (FieldOcc GhcRn)
hsRecFieldLbl = (SrcSpan
-> SrcSpanLess (Located (FieldOcc GhcRn))
-> Located (FieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XCFieldOcc GhcRn -> Located RdrName -> FieldOcc GhcRn
forall pass. XCFieldOcc pass -> Located RdrName -> FieldOcc pass
FieldOcc
                                                          Name
XCFieldOcc GhcRn
sel (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
ll SrcSpanLess (Located RdrName)
lbl)))
                             , hsRecFieldArg :: arg
hsRecFieldArg = arg
arg'
                             , hsRecPun :: Bool
hsRecPun      = Bool
pun })) }
    rn_fld _ _ (LHsRecField GhcPs arg
-> Located (SrcSpanLess (LHsRecField GhcPs arg))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (HsRecField (dL->L _ (XFieldOcc _)) _ _))
      = String -> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg)
forall a. String -> a
panic "rnHsRecFields"
    rn_fld _ _ _ = String -> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecField GhcRn arg)
forall a. String -> a
panic "rn_fld: Impossible Match"
                                -- due to #15884


    rn_dotdot :: Maybe Int      -- See Note [DotDot fields] in HsPat
              -> Maybe Name -- The constructor (Nothing for an
                                --    out of scope constructor)
              -> [LHsRecField GhcRn arg] -- Explicit fields
              -> RnM [LHsRecField GhcRn arg]   -- Filled in .. fields
    rn_dotdot :: Maybe Int
-> Maybe Name
-> [LHsRecField GhcRn arg]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsRecField GhcRn arg]
rn_dotdot (Just n :: Int
n) (Just con :: Name
con) flds :: [LHsRecField GhcRn arg]
flds -- ".." on record construction / pat match
      | Bool -> Bool
not (Name -> Bool
isUnboundName Name
con) -- This test is because if the constructor
                                -- isn't in scope the constructor lookup will add
                                -- an error but still return an unbound name. We
                                -- don't want that to screw up the dot-dot fill-in stuff.
      = ASSERT( flds `lengthIs` n )
        do { SrcSpan
loc <- RnM SrcSpan
getSrcSpanM -- Rather approximate
           ; Bool
dd_flag <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.RecordWildCards
           ; Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkErr Bool
dd_flag (HsRecFieldContext -> MsgDoc
needFlagDotDot HsRecFieldContext
ctxt)
           ; (rdr_env :: GlobalRdrEnv
rdr_env, lcl_env :: LocalRdrEnv
lcl_env) <- TcRn (GlobalRdrEnv, LocalRdrEnv)
getRdrEnvs
           ; [FieldLabel]
con_fields <- Name -> RnM [FieldLabel]
lookupConstructorFields Name
con
           ; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([FieldLabel] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FieldLabel]
con_fields) (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr (Name -> MsgDoc
badDotDotCon Name
con))
           ; let present_flds :: OccSet
present_flds = [OccName] -> OccSet
mkOccSet ([OccName] -> OccSet) -> [OccName] -> OccSet
forall a b. (a -> b) -> a -> b
$ (RdrName -> OccName) -> [RdrName] -> [OccName]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> OccName
rdrNameOcc ([LHsRecField GhcRn arg] -> [RdrName]
forall id arg. [LHsRecField id arg] -> [RdrName]
getFieldLbls [LHsRecField GhcRn arg]
flds)

                   -- For constructor uses (but not patterns)
                   -- the arg should be in scope locally;
                   -- i.e. not top level or imported
                   -- Eg.  data R = R { x,y :: Int }
                   --      f x = R { .. }   -- Should expand to R {x=x}, not R{x=x,y=y}
                 arg_in_scope :: OccName -> Bool
arg_in_scope lbl :: OccName
lbl = OccName -> RdrName
mkRdrUnqual OccName
lbl RdrName -> LocalRdrEnv -> Bool
`elemLocalRdrEnv` LocalRdrEnv
lcl_env

                 (dot_dot_fields :: [FieldLabel]
dot_dot_fields, dot_dot_gres :: [GlobalRdrElt]
dot_dot_gres)
                        = [(FieldLabel, GlobalRdrElt)] -> ([FieldLabel], [GlobalRdrElt])
forall a b. [(a, b)] -> ([a], [b])
unzip [ (FieldLabel
fl, GlobalRdrElt
gre)
                                | FieldLabel
fl <- [FieldLabel]
con_fields
                                , let lbl :: OccName
lbl = FastString -> OccName
mkVarOccFS (FieldLabel -> FastString
forall a. FieldLbl a -> FastString
flLabel FieldLabel
fl)
                                , Bool -> Bool
not (OccName
lbl OccName -> OccSet -> Bool
`elemOccSet` OccSet
present_flds)
                                , Just gre :: GlobalRdrElt
gre <- [GlobalRdrEnv -> FieldLabel -> Maybe GlobalRdrElt
lookupGRE_FieldLabel GlobalRdrEnv
rdr_env FieldLabel
fl]
                                              -- Check selector is in scope
                                , case HsRecFieldContext
ctxt of
                                    HsRecFieldCon {} -> OccName -> Bool
arg_in_scope OccName
lbl
                                    _other :: HsRecFieldContext
_other           -> Bool
True ]

           ; [GlobalRdrElt] -> IOEnv (Env TcGblEnv TcLclEnv) ()
addUsedGREs [GlobalRdrElt]
dot_dot_gres
           ; [LHsRecField GhcRn arg]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsRecField GhcRn arg]
forall (m :: * -> *) a. Monad m => a -> m a
return [ SrcSpan
-> SrcSpanLess (LHsRecField GhcRn arg) -> LHsRecField GhcRn arg
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (HsRecField :: forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField
                        { hsRecFieldLbl :: Located (FieldOcc GhcRn)
hsRecFieldLbl = SrcSpan
-> SrcSpanLess (Located (FieldOcc GhcRn))
-> Located (FieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XCFieldOcc GhcRn -> Located RdrName -> FieldOcc GhcRn
forall pass. XCFieldOcc pass -> Located RdrName -> FieldOcc pass
FieldOcc Name
XCFieldOcc GhcRn
sel (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
arg_rdr))
                        , hsRecFieldArg :: arg
hsRecFieldArg = SrcSpan -> SrcSpanLess arg -> arg
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (SrcSpan -> RdrName -> SrcSpanLess arg
mk_arg SrcSpan
loc RdrName
arg_rdr)
                        , hsRecPun :: Bool
hsRecPun      = Bool
False })
                    | FieldLabel
fl <- [FieldLabel]
dot_dot_fields
                    , let sel :: Name
sel     = FieldLabel -> Name
forall a. FieldLbl a -> a
flSelector FieldLabel
fl
                    , let arg_rdr :: RdrName
arg_rdr = FastString -> RdrName
mkVarUnqual (FieldLabel -> FastString
forall a. FieldLbl a -> FastString
flLabel FieldLabel
fl) ] }

    rn_dotdot _dotdot :: Maybe Int
_dotdot _mb_con :: Maybe Name
_mb_con _flds :: [LHsRecField GhcRn arg]
_flds
      = [LHsRecField GhcRn arg]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsRecField GhcRn arg]
forall (m :: * -> *) a. Monad m => a -> m a
return []
      -- _dotdot = Nothing => No ".." at all
      -- _mb_con = Nothing => Record update
      -- _mb_con = Just unbound => Out of scope data constructor

    dup_flds :: [NE.NonEmpty RdrName]
        -- Each list represents a RdrName that occurred more than once
        -- (the list contains all occurrences)
        -- Each list in dup_fields is non-empty
    (_, dup_flds :: [NonEmpty RdrName]
dup_flds) = (RdrName -> RdrName -> Ordering)
-> [RdrName] -> ([RdrName], [NonEmpty RdrName])
forall a. (a -> a -> Ordering) -> [a] -> ([a], [NonEmpty a])
removeDups RdrName -> RdrName -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ([LHsRecField GhcPs arg] -> [RdrName]
forall id arg. [LHsRecField id arg] -> [RdrName]
getFieldLbls [LHsRecField GhcPs arg]
flds)


-- NB: Consider this:
--      module Foo where { data R = R { fld :: Int } }
--      module Odd where { import Foo; fld x = x { fld = 3 } }
-- Arguably this should work, because the reference to 'fld' is
-- unambiguous because there is only one field id 'fld' in scope.
-- But currently it's rejected.

rnHsRecUpdFields
    :: [LHsRecUpdField GhcPs]
    -> RnM ([LHsRecUpdField GhcRn], FreeVars)
rnHsRecUpdFields :: [LHsRecUpdField GhcPs] -> RnM ([LHsRecUpdField GhcRn], FreeVars)
rnHsRecUpdFields flds :: [LHsRecUpdField GhcPs]
flds
  = do { Bool
pun_ok        <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.RecordPuns
       ; Bool
overload_ok   <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DuplicateRecordFields
       ; (flds1 :: [LHsRecUpdField GhcRn]
flds1, fvss :: [FreeVars]
fvss) <- (LHsRecUpdField GhcPs
 -> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcRn, FreeVars))
-> [LHsRecUpdField GhcPs]
-> IOEnv
     (Env TcGblEnv TcLclEnv) ([LHsRecUpdField GhcRn], [FreeVars])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
mapAndUnzipM (Bool
-> Bool
-> LHsRecUpdField GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcRn, FreeVars)
rn_fld Bool
pun_ok Bool
overload_ok) [LHsRecUpdField GhcPs]
flds
       ; (NonEmpty RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [NonEmpty RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> (NonEmpty RdrName -> MsgDoc)
-> NonEmpty RdrName
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecFieldContext -> NonEmpty RdrName -> MsgDoc
dupFieldErr HsRecFieldContext
HsRecFieldUpd) [NonEmpty RdrName]
dup_flds

       -- Check for an empty record update  e {}
       -- NB: don't complain about e { .. }, because rn_dotdot has done that already
       ; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([LHsRecUpdField GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsRecUpdField GhcPs]
flds) (IOEnv (Env TcGblEnv TcLclEnv) ()
 -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr MsgDoc
emptyUpdateErr

       ; ([LHsRecUpdField GhcRn], FreeVars)
-> RnM ([LHsRecUpdField GhcRn], FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsRecUpdField GhcRn]
flds1, [FreeVars] -> FreeVars
plusFVs [FreeVars]
fvss) }
  where
    doc :: MsgDoc
doc = String -> MsgDoc
text "constructor field name"

    rn_fld :: Bool -> Bool -> LHsRecUpdField GhcPs
           -> RnM (LHsRecUpdField GhcRn, FreeVars)
    rn_fld :: Bool
-> Bool
-> LHsRecUpdField GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcRn, FreeVars)
rn_fld pun_ok :: Bool
pun_ok overload_ok :: Bool
overload_ok (LHsRecUpdField GhcPs
-> Located (SrcSpanLess (LHsRecUpdField GhcPs))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l (HsRecField { hsRecFieldLbl = dL->L loc f
                                                   , hsRecFieldArg = arg
                                                   , hsRecPun      = pun }))
      = do { let lbl :: RdrName
lbl = AmbiguousFieldOcc GhcPs -> RdrName
forall (p :: Pass). AmbiguousFieldOcc (GhcPass p) -> RdrName
rdrNameAmbiguousFieldOcc SrcSpanLess (Located (AmbiguousFieldOcc GhcPs))
AmbiguousFieldOcc GhcPs
f
           ; Either Name [Name]
sel <- SrcSpan -> TcRn (Either Name [Name]) -> TcRn (Either Name [Name])
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcRn (Either Name [Name]) -> TcRn (Either Name [Name]))
-> TcRn (Either Name [Name]) -> TcRn (Either Name [Name])
forall a b. (a -> b) -> a -> b
$
                      -- Defer renaming of overloaded fields to the typechecker
                      -- See Note [Disambiguating record fields] in TcExpr
                      if Bool
overload_ok
                          then do { Maybe (Either Name [Name])
mb <- Bool -> RdrName -> RnM (Maybe (Either Name [Name]))
lookupGlobalOccRn_overloaded
                                            Bool
overload_ok RdrName
lbl
                                  ; case Maybe (Either Name [Name])
mb of
                                      Nothing ->
                                        do { MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr
                                               (MsgDoc -> RdrName -> MsgDoc
unknownSubordinateErr MsgDoc
doc RdrName
lbl)
                                           ; Either Name [Name] -> TcRn (Either Name [Name])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name] -> Either Name [Name]
forall a b. b -> Either a b
Right []) }
                                      Just r :: Either Name [Name]
r  -> Either Name [Name] -> TcRn (Either Name [Name])
forall (m :: * -> *) a. Monad m => a -> m a
return Either Name [Name]
r }
                          else (Name -> Either Name [Name])
-> RnM Name -> TcRn (Either Name [Name])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Name -> Either Name [Name]
forall a b. a -> Either a b
Left (RnM Name -> TcRn (Either Name [Name]))
-> RnM Name -> TcRn (Either Name [Name])
forall a b. (a -> b) -> a -> b
$ RdrName -> RnM Name
lookupGlobalOccRn RdrName
lbl
           ; LHsExpr GhcPs
arg' <- if Bool
pun
                     then do { Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkErr Bool
pun_ok (Located RdrName -> MsgDoc
badPun (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
lbl))
                               -- Discard any module qualifier (#11662)
                             ; let arg_rdr :: RdrName
arg_rdr = OccName -> RdrName
mkRdrUnqual (RdrName -> OccName
rdrNameOcc RdrName
lbl)
                             ; LHsExpr GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) (LHsExpr GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XVar GhcPs -> Located (IdP GhcPs) -> HsExpr GhcPs
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcPs
NoExt
noExt (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
arg_rdr))) }
                     else LHsExpr GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) (LHsExpr GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return LHsExpr GhcPs
arg
           ; (arg'' :: LHsExpr GhcRn
arg'', fvs :: FreeVars
fvs) <- LHsExpr GhcPs -> RnM (LHsExpr GhcRn, FreeVars)
rnLExpr LHsExpr GhcPs
arg'

           ; let fvs' :: FreeVars
fvs' = case Either Name [Name]
sel of
                          Left sel_name :: Name
sel_name -> FreeVars
fvs FreeVars -> Name -> FreeVars
`addOneFV` Name
sel_name
                          Right [sel_name :: Name
sel_name] -> FreeVars
fvs FreeVars -> Name -> FreeVars
`addOneFV` Name
sel_name
                          Right _       -> FreeVars
fvs
                 lbl' :: Located (AmbiguousFieldOcc GhcRn)
lbl' = case Either Name [Name]
sel of
                          Left sel_name :: Name
sel_name ->
                                     SrcSpan
-> SrcSpanLess (Located (AmbiguousFieldOcc GhcRn))
-> Located (AmbiguousFieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XUnambiguous GhcRn -> Located RdrName -> AmbiguousFieldOcc GhcRn
forall pass.
XUnambiguous pass -> Located RdrName -> AmbiguousFieldOcc pass
Unambiguous Name
XUnambiguous GhcRn
sel_name  (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
lbl))
                          Right [sel_name :: Name
sel_name] ->
                                     SrcSpan
-> SrcSpanLess (Located (AmbiguousFieldOcc GhcRn))
-> Located (AmbiguousFieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XUnambiguous GhcRn -> Located RdrName -> AmbiguousFieldOcc GhcRn
forall pass.
XUnambiguous pass -> Located RdrName -> AmbiguousFieldOcc pass
Unambiguous Name
XUnambiguous GhcRn
sel_name  (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
lbl))
                          Right _ -> SrcSpan
-> SrcSpanLess (Located (AmbiguousFieldOcc GhcRn))
-> Located (AmbiguousFieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XAmbiguous GhcRn -> Located RdrName -> AmbiguousFieldOcc GhcRn
forall pass.
XAmbiguous pass -> Located RdrName -> AmbiguousFieldOcc pass
Ambiguous   XAmbiguous GhcRn
NoExt
noExt     (SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (Located RdrName)
RdrName
lbl))

           ; (LHsRecUpdField GhcRn, FreeVars)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcRn, FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> SrcSpanLess (LHsRecUpdField GhcRn) -> LHsRecUpdField GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l (HsRecField :: forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField { hsRecFieldLbl :: Located (AmbiguousFieldOcc GhcRn)
hsRecFieldLbl = Located (AmbiguousFieldOcc GhcRn)
lbl'
                                      , hsRecFieldArg :: LHsExpr GhcRn
hsRecFieldArg = LHsExpr GhcRn
arg''
                                      , hsRecPun :: Bool
hsRecPun      = Bool
pun }), FreeVars
fvs') }

    dup_flds :: [NE.NonEmpty RdrName]
        -- Each list represents a RdrName that occurred more than once
        -- (the list contains all occurrences)
        -- Each list in dup_fields is non-empty
    (_, dup_flds :: [NonEmpty RdrName]
dup_flds) = (RdrName -> RdrName -> Ordering)
-> [RdrName] -> ([RdrName], [NonEmpty RdrName])
forall a. (a -> a -> Ordering) -> [a] -> ([a], [NonEmpty a])
removeDups RdrName -> RdrName -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ([LHsRecUpdField GhcPs] -> [RdrName]
getFieldUpdLbls [LHsRecUpdField GhcPs]
flds)



getFieldIds :: [LHsRecField GhcRn arg] -> [Name]
getFieldIds :: [LHsRecField GhcRn arg] -> [Name]
getFieldIds flds :: [LHsRecField GhcRn arg]
flds = (LHsRecField GhcRn arg -> Name)
-> [LHsRecField GhcRn arg] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located Name -> Name)
-> (LHsRecField GhcRn arg -> Located Name)
-> LHsRecField GhcRn arg
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecField GhcRn arg -> Located Name
forall pass arg. HsRecField pass arg -> Located (XCFieldOcc pass)
hsRecFieldSel (HsRecField GhcRn arg -> Located Name)
-> (LHsRecField GhcRn arg -> HsRecField GhcRn arg)
-> LHsRecField GhcRn arg
-> Located Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsRecField GhcRn arg -> HsRecField GhcRn arg
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LHsRecField GhcRn arg]
flds

getFieldLbls :: [LHsRecField id arg] -> [RdrName]
getFieldLbls :: [LHsRecField id arg] -> [RdrName]
getFieldLbls flds :: [LHsRecField id arg]
flds
  = (LHsRecField id arg -> RdrName)
-> [LHsRecField id arg] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map (Located RdrName -> RdrName
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located RdrName -> RdrName)
-> (LHsRecField id arg -> Located RdrName)
-> LHsRecField id arg
-> RdrName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldOcc id -> Located RdrName
forall pass. FieldOcc pass -> Located RdrName
rdrNameFieldOcc (FieldOcc id -> Located RdrName)
-> (LHsRecField id arg -> FieldOcc id)
-> LHsRecField id arg
-> Located RdrName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (FieldOcc id) -> FieldOcc id
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located (FieldOcc id) -> FieldOcc id)
-> (LHsRecField id arg -> Located (FieldOcc id))
-> LHsRecField id arg
-> FieldOcc id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecField' (FieldOcc id) arg -> Located (FieldOcc id)
forall id arg. HsRecField' id arg -> Located id
hsRecFieldLbl (HsRecField' (FieldOcc id) arg -> Located (FieldOcc id))
-> (LHsRecField id arg -> HsRecField' (FieldOcc id) arg)
-> LHsRecField id arg
-> Located (FieldOcc id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsRecField id arg -> HsRecField' (FieldOcc id) arg
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LHsRecField id arg]
flds

getFieldUpdLbls :: [LHsRecUpdField GhcPs] -> [RdrName]
getFieldUpdLbls :: [LHsRecUpdField GhcPs] -> [RdrName]
getFieldUpdLbls flds :: [LHsRecUpdField GhcPs]
flds = (LHsRecUpdField GhcPs -> RdrName)
-> [LHsRecUpdField GhcPs] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map (AmbiguousFieldOcc GhcPs -> RdrName
forall (p :: Pass). AmbiguousFieldOcc (GhcPass p) -> RdrName
rdrNameAmbiguousFieldOcc (AmbiguousFieldOcc GhcPs -> RdrName)
-> (LHsRecUpdField GhcPs -> AmbiguousFieldOcc GhcPs)
-> LHsRecUpdField GhcPs
-> RdrName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (AmbiguousFieldOcc GhcPs) -> AmbiguousFieldOcc GhcPs
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located (AmbiguousFieldOcc GhcPs) -> AmbiguousFieldOcc GhcPs)
-> (LHsRecUpdField GhcPs -> Located (AmbiguousFieldOcc GhcPs))
-> LHsRecUpdField GhcPs
-> AmbiguousFieldOcc GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecField' (AmbiguousFieldOcc GhcPs) (LHsExpr GhcPs)
-> Located (AmbiguousFieldOcc GhcPs)
forall id arg. HsRecField' id arg -> Located id
hsRecFieldLbl (HsRecField' (AmbiguousFieldOcc GhcPs) (LHsExpr GhcPs)
 -> Located (AmbiguousFieldOcc GhcPs))
-> (LHsRecUpdField GhcPs
    -> HsRecField' (AmbiguousFieldOcc GhcPs) (LHsExpr GhcPs))
-> LHsRecUpdField GhcPs
-> Located (AmbiguousFieldOcc GhcPs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsRecUpdField GhcPs
-> HsRecField' (AmbiguousFieldOcc GhcPs) (LHsExpr GhcPs)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LHsRecUpdField GhcPs]
flds

needFlagDotDot :: HsRecFieldContext -> SDoc
needFlagDotDot :: HsRecFieldContext -> MsgDoc
needFlagDotDot ctxt :: HsRecFieldContext
ctxt = [MsgDoc] -> MsgDoc
vcat [String -> MsgDoc
text "Illegal `..' in record" MsgDoc -> MsgDoc -> MsgDoc
<+> HsRecFieldContext -> MsgDoc
pprRFC HsRecFieldContext
ctxt,
                            String -> MsgDoc
text "Use RecordWildCards to permit this"]

badDotDotCon :: Name -> SDoc
badDotDotCon :: Name -> MsgDoc
badDotDotCon con :: Name
con
  = [MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text "Illegal `..' notation for constructor" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
con)
         , Int -> MsgDoc -> MsgDoc
nest 2 (String -> MsgDoc
text "The constructor has no labelled fields") ]

emptyUpdateErr :: SDoc
emptyUpdateErr :: MsgDoc
emptyUpdateErr = String -> MsgDoc
text "Empty record update"

badPun :: Located RdrName -> SDoc
badPun :: Located RdrName -> MsgDoc
badPun fld :: Located RdrName
fld = [MsgDoc] -> MsgDoc
vcat [String -> MsgDoc
text "Illegal use of punning for field" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Located RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Located RdrName
fld),
                   String -> MsgDoc
text "Use NamedFieldPuns to permit this"]

dupFieldErr :: HsRecFieldContext -> NE.NonEmpty RdrName -> SDoc
dupFieldErr :: HsRecFieldContext -> NonEmpty RdrName -> MsgDoc
dupFieldErr ctxt :: HsRecFieldContext
ctxt dups :: NonEmpty RdrName
dups
  = [MsgDoc] -> MsgDoc
hsep [String -> MsgDoc
text "duplicate field name",
          MsgDoc -> MsgDoc
quotes (RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr (NonEmpty RdrName -> RdrName
forall a. NonEmpty a -> a
NE.head NonEmpty RdrName
dups)),
          String -> MsgDoc
text "in record", HsRecFieldContext -> MsgDoc
pprRFC HsRecFieldContext
ctxt]

pprRFC :: HsRecFieldContext -> SDoc
pprRFC :: HsRecFieldContext -> MsgDoc
pprRFC (HsRecFieldCon {}) = String -> MsgDoc
text "construction"
pprRFC (HsRecFieldPat {}) = String -> MsgDoc
text "pattern"
pprRFC (HsRecFieldUpd {}) = String -> MsgDoc
text "update"

{-
************************************************************************
*                                                                      *
\subsubsection{Literals}
*                                                                      *
************************************************************************

When literals occur we have to make sure
that the types and classes they involve
are made available.
-}

rnLit :: HsLit p -> RnM ()
rnLit :: HsLit p -> IOEnv (Env TcGblEnv TcLclEnv) ()
rnLit (HsChar _ c :: Char
c) = Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkErr (Char -> Bool
inCharRange Char
c) (Char -> MsgDoc
bogusCharError Char
c)
rnLit _ = () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- Turn a Fractional-looking literal which happens to be an integer into an
-- Integer-looking literal.
generalizeOverLitVal :: OverLitVal -> OverLitVal
generalizeOverLitVal :: OverLitVal -> OverLitVal
generalizeOverLitVal (HsFractional (FL {fl_text :: FractionalLit -> SourceText
fl_text=SourceText
src,fl_neg :: FractionalLit -> Bool
fl_neg=Bool
neg,fl_value :: FractionalLit -> Rational
fl_value=Rational
val}))
    | Rational -> Integer
forall a. Ratio a -> a
denominator Rational
val Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 1 = IntegralLit -> OverLitVal
HsIntegral (IL :: SourceText -> Bool -> Integer -> IntegralLit
IL { il_text :: SourceText
il_text=SourceText
src
                                            , il_neg :: Bool
il_neg=Bool
neg
                                            , il_value :: Integer
il_value=Rational -> Integer
forall a. Ratio a -> a
numerator Rational
val})
generalizeOverLitVal lit :: OverLitVal
lit = OverLitVal
lit

isNegativeZeroOverLit :: HsOverLit t -> Bool
isNegativeZeroOverLit :: HsOverLit t -> Bool
isNegativeZeroOverLit lit :: HsOverLit t
lit
 = case HsOverLit t -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val HsOverLit t
lit of
        HsIntegral i :: IntegralLit
i   -> 0 Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== IntegralLit -> Integer
il_value IntegralLit
i Bool -> Bool -> Bool
&& IntegralLit -> Bool
il_neg IntegralLit
i
        HsFractional f :: FractionalLit
f -> 0 Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
== FractionalLit -> Rational
fl_value FractionalLit
f Bool -> Bool -> Bool
&& FractionalLit -> Bool
fl_neg FractionalLit
f
        _              -> Bool
False

{-
Note [Negative zero]
~~~~~~~~~~~~~~~~~~~~~~~~~
There were problems with negative zero in conjunction with Negative Literals
extension. Numeric literal value is contained in Integer and Rational types
inside IntegralLit and FractionalLit. These types cannot represent negative
zero value. So we had to add explicit field 'neg' which would hold information
about literal sign. Here in rnOverLit we use it to detect negative zeroes and
in this case return not only literal itself but also negateName so that users
can apply it explicitly. In this case it stays negative zero.  Trac #13211
-}

rnOverLit :: HsOverLit t ->
             RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
rnOverLit :: HsOverLit t
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
rnOverLit origLit :: HsOverLit t
origLit
  = do  { Bool
opt_NumDecimals <- Extension -> RnM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.NumDecimals
        ; let { lit :: HsOverLit t
lit@(OverLit {ol_val :: forall p. HsOverLit p -> OverLitVal
ol_val=OverLitVal
val})
            | Bool
opt_NumDecimals = HsOverLit t
origLit {ol_val :: OverLitVal
ol_val = OverLitVal -> OverLitVal
generalizeOverLitVal (HsOverLit t -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val HsOverLit t
origLit)}
            | Bool
otherwise       = HsOverLit t
origLit
          }
        ; let std_name :: Name
std_name = OverLitVal -> Name
hsOverLitName OverLitVal
val
        ; (SyntaxExpr { syn_expr :: forall p. SyntaxExpr p -> HsExpr p
syn_expr = HsExpr GhcRn
from_thing_name }, fvs1 :: FreeVars
fvs1)
            <- Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
std_name
        ; let rebindable :: Bool
rebindable = case HsExpr GhcRn
from_thing_name of
                                HsVar _ lv :: Located (IdP GhcRn)
lv -> (Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
lv) Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= Name
std_name
                                _          -> String -> Bool
forall a. String -> a
panic "rnOverLit"
        ; let lit' :: HsOverLit GhcRn
lit' = HsOverLit t
lit { ol_witness :: HsExpr GhcRn
ol_witness = HsExpr GhcRn
from_thing_name
                         , ol_ext :: XOverLit GhcRn
ol_ext = Bool
XOverLit GhcRn
rebindable }
        ; if HsOverLit GhcRn -> Bool
forall t. HsOverLit t -> Bool
isNegativeZeroOverLit HsOverLit GhcRn
lit'
          then do { (SyntaxExpr { syn_expr :: forall p. SyntaxExpr p -> HsExpr p
syn_expr = HsExpr GhcRn
negate_name }, fvs2 :: FreeVars
fvs2)
                      <- Name -> RnM (SyntaxExpr GhcRn, FreeVars)
lookupSyntaxName Name
negateName
                  ; ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return ((HsOverLit GhcRn
lit' { ol_val :: OverLitVal
ol_val = OverLitVal -> OverLitVal
negateOverLitVal OverLitVal
val }, HsExpr GhcRn -> Maybe (HsExpr GhcRn)
forall a. a -> Maybe a
Just HsExpr GhcRn
negate_name)
                                  , FreeVars
fvs1 FreeVars -> FreeVars -> FreeVars
`plusFV` FreeVars
fvs2) }
          else ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
-> RnM ((HsOverLit GhcRn, Maybe (HsExpr GhcRn)), FreeVars)
forall (m :: * -> *) a. Monad m => a -> m a
return ((HsOverLit GhcRn
lit', Maybe (HsExpr GhcRn)
forall a. Maybe a
Nothing), FreeVars
fvs1) }

{-
************************************************************************
*                                                                      *
\subsubsection{Errors}
*                                                                      *
************************************************************************
-}

patSigErr :: Outputable a => a -> SDoc
patSigErr :: a -> MsgDoc
patSigErr ty :: a
ty
  =  (String -> MsgDoc
text "Illegal signature in pattern:" MsgDoc -> MsgDoc -> MsgDoc
<+> a -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr a
ty)
        MsgDoc -> MsgDoc -> MsgDoc
$$ Int -> MsgDoc -> MsgDoc
nest 4 (String -> MsgDoc
text "Use ScopedTypeVariables to permit it")

bogusCharError :: Char -> SDoc
bogusCharError :: Char -> MsgDoc
bogusCharError c :: Char
c
  = String -> MsgDoc
text "character literal out of range: '\\" MsgDoc -> MsgDoc -> MsgDoc
<> Char -> MsgDoc
char Char
c  MsgDoc -> MsgDoc -> MsgDoc
<> Char -> MsgDoc
char '\''

badViewPat :: Pat GhcPs -> SDoc
badViewPat :: LPat GhcPs -> MsgDoc
badViewPat pat :: LPat GhcPs
pat = [MsgDoc] -> MsgDoc
vcat [String -> MsgDoc
text "Illegal view pattern: " MsgDoc -> MsgDoc -> MsgDoc
<+> LPat GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr LPat GhcPs
pat,
                       String -> MsgDoc
text "Use ViewPatterns to enable view patterns"]