@@ -298,8 +298,9 @@ elabCon info syn tn codata (doc, n, t_in, fc)
298elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
298elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
299elabClauses info fc opts n_in cs = let n = liftname info n_in in
299elabClauses info fc opts n_in cs = let n = liftname info n_in in
300 do ctxt <- getContext
300 do ctxt <- getContext
301− -- Check n actually exists
301+ -- Check n actually exists, with no definition yet
302 let tys = lookupTy Nothing n ctxt
302 let tys = lookupTy Nothing n ctxt
303+ checkUndefined n ctxt
303 unless (length tys > 1) $ do
304 unless (length tys > 1) $ do
304 fty <- case tys of
305 fty <- case tys of
305 [] -> -- TODO: turn into a CAF if there's no arguments
306 [] -> -- TODO: turn into a CAF if there's no arguments
@@ -421,6 +422,11 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
421 [] -> return ()
422 [] -> return ()
422 return ()
423 return ()
425+ checkUndefined n ctxt = case lookupDef Nothing n ctxt of
427+ [TyDecl _ _] -> return ()
428+ _ -> tclift $ tfail (At fc (AlreadyDefined n))
424 debind (Right (x, y)) = let (vs, x') = depat [] x
430 debind (Right (x, y)) = let (vs, x') = depat [] x
425 (_, y') = depat [] y in
431 (_, y') = depat [] y in
426 (vs, x', y')
432 (vs, x', y')