@@ -54,7 +54,7 @@ elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
54 = do let codata = Codata `elem` opts
54 = do let codata = Codata `elem` opts
55 iLOG (show (fc, doc))
55 iLOG (show (fc, doc))
56 checkUndefined fc n
56 checkUndefined fc n
57− (cty, t, inacc) <- buildType info syn fc [] n t_in
57+ (cty, _, t, inacc) <- buildType info syn fc [] n t_in
59 addIBC (IBCDef n)
59 addIBC (IBCDef n)
60 updateContext (addTyDecl n (TCon 0 0) cty) -- temporary, to check cons
60 updateContext (addTyDecl n (TCon 0 0) cty) -- temporary, to check cons
@@ -63,7 +63,7 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
63 = do let codata = Codata `elem` opts
63 = do let codata = Codata `elem` opts
64 iLOG (show fc)
64 iLOG (show fc)
65 undef <- isUndefined fc n
65 undef <- isUndefined fc n
66− (cty, t, inacc) <- buildType info syn fc [] n t_in
66+ (cty, _, t, inacc) <- buildType info syn fc [] n t_in
67 -- if n is defined already, make sure it is just a type declaration
67 -- if n is defined already, make sure it is just a type declaration
68 -- with the same type we've just elaborated
68 -- with the same type we've just elaborated
69 i <- getIState
69 i <- getIState
@@ -71,7 +71,7 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
71 -- temporary, to check cons
71 -- temporary, to check cons
72 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
72 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
73 let cnameinfo = cinfo info (map cname dcons)
73 let cnameinfo = cinfo info (map cname dcons)
74− cons <- mapM (elabCon cnameinfo syn n codata) dcons
74+ cons <- mapM (elabCon cnameinfo syn n codata (getRetTy cty)) dcons
75 ttag <- getName
75 ttag <- getName
76 i <- getIState
76 i <- getIState
77 let as = map (const Nothing) (getArgTys cty)
77 let as = map (const Nothing) (getArgTys cty)
@@ -203,12 +203,15 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
203-- TODO: the above is a comment from the past;
203-- TODO: the above is a comment from the past;
204-- forcenames is probably no longer needed
204-- forcenames is probably no longer needed
205elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
205elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
206+ Type -> -- for kind checking
206− (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
207+ (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) ->
207−elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
209+elabCon info syn tn codata expkind (doc, argDocs, n, t_in, fc, forcenames)
208 = do checkUndefined fc n
210 = do checkUndefined fc n
209− (cty, t, inacc) <- buildType info syn fc [Constructor] n (if codata then mkLazy t_in else t_in)
211+ (cty, ckind, t, inacc) <- buildType info syn fc [Constructor] n (if codata then mkLazy t_in else t_in)
210 ctxt <- getContext
212 ctxt <- getContext
211 let cty' = normalise ctxt [] cty
213 let cty' = normalise ctxt [] cty
214+ checkUniqueKind ckind expkind
213 -- Check that the constructor type is, in fact, a part of the family being defined
216 -- Check that the constructor type is, in fact, a part of the family being defined
214 tyIs n cty'
217 tyIs n cty'
@@ -250,6 +253,15 @@ elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
250 | otherwise = getNamePos (i + 1) sc x
253 | otherwise = getNamePos (i + 1) sc x
251 getNamePos _ _ _ = Nothing
254 getNamePos _ _ _ = Nothing
256+ -- if the constructor is a UniqueType, the datatype must be too
257+ -- (Type* is fine, since that is checked for uniqueness too)
258+ checkUniqueKind (UType UniqueType) (UType UniqueType) = return ()
259+ checkUniqueKind (UType UniqueType) (UType AllTypes) = return ()
260+ checkUniqueKind (UType UniqueType) (TType _)
261+ = tclift $ tfail (UniqueKindError n)
262+ checkUniqueKind (UType AllTypes) _ = return ()
263+ checkUniqueKind (TType _) _ = return ()
253type EliminatorState = StateT (Map.Map String Int) Idris
265type EliminatorState = StateT (Map.Map String Int) Idris
255-- TODO: Rewrite everything to use idris_implicits instead of manual splitting (or in TT)
267-- TODO: Rewrite everything to use idris_implicits instead of manual splitting (or in TT)