86519ac0969072bb8654568079fb4c0da7a047a6
[ghc-hetmet.git] / ghc / compiler / typecheck / TcConDecls.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
3 %
4 \section[TcConDecls]{Typechecking @ConDecls@}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module TcConDecls ( tcConDecls ) where
10
11 import TcMonad          -- typechecking monadic machinery
12 import AbsSyn
13
14 import CE               ( CE(..) )
15 import E                ( GVE(..), nullGVE, plusGVE )
16 import Errors           ( confusedNameErr )
17 import Id               ( mkDataCon, SpecEnv )
18 import TCE              ( TCE(..), UniqFM )
19 import TVE              ( TVE(..) )
20 import TcMonoType       ( tcMonoType )
21 import Util
22 \end{code}
23
24 \begin{code}
25 tcConDecls :: TCE -> TVE -> TyCon -> [TyVarTemplate] -> SpecEnv
26            -> [RenamedConDecl] -> Baby_TcM GVE
27
28 tcConDecls tce tve tycon tyvars specenv [] = returnB_Tc nullGVE
29
30 tcConDecls tce tve tycon tyvars specenv (cd:cds) 
31   = tc_decl cd                                  `thenB_Tc` \ gve_fst ->
32     tcConDecls tce tve tycon tyvars specenv cds `thenB_Tc` \ gve_rest ->
33     returnB_Tc (plusGVE gve_fst gve_rest)
34   where
35     tc_decl (ConDecl name@(OtherTopId uniq full_name) tys src_loc)
36       = addSrcLocB_Tc src_loc                    (
37         mapB_Tc (tcMonoType fake_CE tce tve) tys `thenB_Tc` \ arg_tys ->
38         returnB_Tc [(name, data_con arg_tys)]
39         )
40       where
41         fake_CE = panic "tcConDecls:CE"
42
43         data_con arg_tys
44           = mkDataCon uniq
45                       full_name
46                       tyvars
47                       [{-no context-}]
48                       arg_tys
49                       tycon
50                       specenv
51
52     tc_decl (ConDecl odd_name _ src_loc)
53       = failB_Tc (confusedNameErr "Bad name for a data constructor (a Prelude name?)"
54                     odd_name src_loc)
55 \end{code}