From c92e8403bbd92b3fa36bd891c6126e0a1fad8fd0 Mon Sep 17 00:00:00 2001
From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= <astor.jeremie@wanadoo.fr>
Date: Tue, 12 May 2020 23:09:03 +0200
Subject: [PATCH] :art: Improve Func_Base scan

---
 src/parse/scan0.c | 20 --------------------
 src/parse/scan1.c | 24 ++++++++++++++++++++++--
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/parse/scan0.c b/src/parse/scan0.c
index ee022da9..a1c4399f 100644
--- a/src/parse/scan0.c
+++ b/src/parse/scan0.c
@@ -67,30 +67,10 @@ static void fptr_def(const Env env, const Fptr_Def fptr) {
   def->base->func = fptr->base->func;
 }
 
-ANN static m_bool check_tmpl_args(const Env env, const Func_Base *base) {
-  ID_List id = base->tmpl->list;
-  do nspc_add_type(env->curr, id->xid, env->gwion->type[et_undefined]);
-  while((id = id->next));
-  Arg_List arg = base->args;
-  do CHECK_OB(known_type(env, arg->td))
-  while((arg = arg->next));
-  return GW_OK;
-}
-
-ANN static m_bool scan0_fptr_args(const Env env, const Fptr_Def fptr) {
-  nspc_push_type(env->gwion->mp, env->curr);
-  const m_bool ret = check_tmpl_args(env, fptr->base);
-  nspc_pop_type(env->gwion->mp, env->curr);
-  return ret;
-}
-
 ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) {
   CHECK_BB(env_access(env, fptr->base->td->flag, td_pos(fptr->base->td)))
-  CHECK_OB(known_type(env, fptr->base->td))
   CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td)));
   const m_str name = s_name(fptr->base->xid);
-  if(fptr->base->tmpl && fptr->base->args)
-    CHECK_BB(scan0_fptr_args(env, fptr))
   const Type t = scan0_type(env, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]);
   t->e->owner = !(!env->class_def && GET_FLAG(fptr->base->td, global)) ?
     env->curr : env->global_nspc;
diff --git a/src/parse/scan1.c b/src/parse/scan1.c
index 8a6bbf32..3840d5fc 100644
--- a/src/parse/scan1.c
+++ b/src/parse/scan1.c
@@ -311,9 +311,29 @@ ANN static m_bool scan1_args(const Env env, Arg_List list) {
   return GW_OK;
 }
 
+ANN static m_bool _scan1_fdef_base_tmpl(const Env env, Func_Base *base) {
+  ID_List id = base->tmpl->list;
+  do nspc_add_type(env->curr, id->xid, env->gwion->type[et_undefined]);
+  while((id = id->next));
+  CHECK_OB((base->ret_type = known_type(env, base->td)))
+  if(base->args) {
+    Arg_List arg = base->args;
+    do CHECK_OB(known_type(env, arg->td))
+    while((arg = arg->next));
+  }
+  return GW_OK;
+}
+
+ANN static m_bool scan1_fdef_base_tmpl(const Env env, Func_Base *base) {
+  nspc_push_type(env->gwion->mp, env->curr);
+  const m_bool ret = _scan1_fdef_base_tmpl(env, base);
+  nspc_pop_type(env->gwion->mp, env->curr);
+  return ret;
+}
+
 ANN m_bool scan1_fptr_def(const Env env, const Fptr_Def fptr) {
   if(tmpl_base(fptr->base->tmpl))
-    return GW_OK;
+    return scan1_fdef_base_tmpl(env, fptr->base);
   if(!fptr->base->func) {
     fptr->base->func = nspc_lookup_value0(env->curr, fptr->base->xid)->d.func_ref;
     fptr->type = nspc_lookup_type0(env->curr, fptr->base->xid);
@@ -473,7 +493,7 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) {
   if(fdef->base->td)
     CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td)))
   if(tmpl_base(fdef->base->tmpl))
-    return GW_OK;
+    return scan1_fdef_base_tmpl(env, fdef->base);
   struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func;
   env->func = &fake;
   ++env->scope->depth;
-- 
2.43.0