From fc49f48c50905af2194f9e751275c61e5f166210 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 27 May 2020 16:23:15 +0200 Subject: [PATCH] :art: Improve infer flag usage --- src/env/env_utils.c | 1 + src/parse/check.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 18fcfc05..5e70f79c 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -80,6 +80,7 @@ ANN static Type class_type(const Env env, const Type base) { t->e->parent = t_class; t->e->ctx = base->e->ctx; t->e->d.base_type = base; + SET_FLAG(t, infer); return t; } diff --git a/src/parse/check.c b/src/parse/check.c index 274cc8cc..617f7996 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -152,6 +152,12 @@ ANN static inline m_bool ensure_check(const Env env, const Type t) { return envset_run(&es, t); } +ANN static inline m_bool inferable(const Env env, const Type t, const loc_t pos) { + if(!GET_FLAG(t, infer)) + return GW_OK; + ERR_B(pos, _("can't infer type.")) +} + ANN static Type_Decl* type2td(const Env env, const Type t, const loc_t loc); ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { if(!decl->td->xid) @@ -166,8 +172,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { ERR_O(td_pos(decl->td), _("can't find type")); { const Type t = get_type(decl->type); - if(GET_FLAG(t, infer)) - ERR_O(td_pos(decl->td), _("can't infer type.")); + CHECK_BO(inferable(env, t, td_pos(decl->td))) if(!GET_FLAG(t, check) && t->e->def) CHECK_BO(ensure_check(env, t)) } @@ -316,6 +321,7 @@ ANN static Type check_prim_id(const Env env, const Symbol *data) { ANN static Type check_prim_typeof(const Env env, const Exp *exp) { const Exp e = *exp; DECL_OO(const Type, t, = check_exp(env, e)) + CHECK_BO(inferable(env, t, (*exp)->pos)) const Type force = force_type(env, t); return type_class(env->gwion, force); } -- 2.43.0