@@ -66,9 +66,10 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
6666 undef <- isUndefined fc n
6767 (cty, _, t, inacc) <- buildType info syn fc [] n t_in
6868 -- if n is defined already, make sure it is just a type declaration
69− -- with the same type we've just elaborated
69+ -- with the same type we've just elaborated, and no constructors
70+ -- yet
7071 i <- getIState
71− checkDefinedAs fc n cty (tt_ctxt i)
72+ checkDefinedAs fc n cty i
7273 -- temporary, to check cons
7374 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
7475 let cnameinfo = cinfo info (map cname dcons)
@@ -124,14 +125,18 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
124125 [oi] -> putIState ist{ idris_optimisation = addDef n oi{ detaggable = True } opt }
125126 _ -> putIState ist{ idris_optimisation = addDef n (Optimise [] True) opt }
126127
127− checkDefinedAs fc n t ctxt
128− = case lookupDef n ctxt of
128+ checkDefinedAs fc n t i
129+ = let defined = tclift $ tfail (At fc (AlreadyDefined n))
130+ ctxt = tt_ctxt i in
131+ case lookupDef n ctxt of
129132 [] -> return ()
130133 [TyDecl _ ty] ->
131134 case converts ctxt [] t ty of
132− OK () -> return ()
133− _ -> tclift $ tfail (At fc (AlreadyDefined n))
134− _ -> tclift $ tfail (At fc (AlreadyDefined n))
135+ OK () -> case lookupCtxtExact n (idris_datatypes i) of
136+ Nothing -> return ()
137+ _ -> defined
138+ _ -> defined
139+ _ -> defined
135140 -- parameters are names which are unchanged across the structure,
136141 -- which appear exactly once in the return type of a constructor
137142