@@ -298,8 +298,9 @@ elabCon info syn tn codata (doc, n, t_in, fc)
298298elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
299299elabClauses info fc opts n_in cs = let n = liftname info n_in in
300300 do ctxt <- getContext
301− -- Check n actually exists
301+ -- Check n actually exists, with no definition yet
302302 let tys = lookupTy Nothing n ctxt
303+ checkUndefined n ctxt
303304 unless (length tys > 1) $ do
304305 fty <- case tys of
305306 [] -> -- 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
421422 [] -> return ()
422423 return ()
423424 where
425+ checkUndefined n ctxt = case lookupDef Nothing n ctxt of
426+ [] -> return ()
427+ [TyDecl _ _] -> return ()
428+ _ -> tclift $ tfail (At fc (AlreadyDefined n))
429+
424430 debind (Right (x, y)) = let (vs, x') = depat [] x
425431 (_, y') = depat [] y in
426432 (vs, x', y')