From: fennecdjay Date: Wed, 4 Sep 2019 00:41:42 +0000 (+0200) Subject: :art: Do not fail on primitive reference X-Git-Tag: nightly~2235 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=28f7270fa8052de7eaf78b459b34a7dd37296cdf;p=gwion.git :art: Do not fail on primitive reference --- diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 1530b3b7..876cef5e 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -98,6 +98,8 @@ OP_CHECK(opck_new) { const Exp_Unary* unary = (Exp_Unary*)data; SET_FLAG(unary->td, ref); DECL_OO(const Type, t, = known_type(env, unary->td)) + if(isa(t, t_object) < 0 && isa(t, t_function) < 0) + ERR_O(exp_self(unary)->pos, _("primitive types cannot be used as reference (@)...\n")) if(type_ref(t)) ERR_N(td_pos(unary->td), _("can't use 'new' on ref type '%s'\n"), t->name) UNSET_FLAG(unary->td, ref); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 2fa307d5..7538d7e5 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -40,7 +40,7 @@ ANN static m_bool type_recursive(const Env env, const Type_Decl *td, const Type } ANN static Type void_type(const Env env, const Type_Decl* td) { - DECL_OO(const Type, type, = known_type_noref(env, td)) + DECL_OO(const Type, type, = known_type(env, td)) { const Type t = get_type(type); if(isa(t, t_object) > 0) @@ -91,7 +91,6 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { t = array_type(env, decl->type, var->array->depth); } else if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref)) ERR_B(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name) - CHECK_OB(prim_ref(env, t, decl->td)) if(env->class_def && isa(t, t_object) > 0) type_contains(env->class_def, t); const Value v = var->value = former ?: new_value(env->gwion->mp, t, s_name(var->xid)); @@ -237,10 +236,8 @@ ANN static m_bool scan1_args(const Env env, Arg_List list) { const Var_Decl var = list->var_decl; if(var->xid) CHECK_BB(isres(env, var->xid, var->pos)) - if(list->td) { + if(list->td) CHECK_OB((list->type = void_type(env, list->td))) - CHECK_OB(prim_ref(env, list->type, list->td)) - } } while((list = list->next)); return GW_OK; } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index fd53fd63..e9fb5dcc 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -69,21 +69,8 @@ ANN static inline void* type_unknown(const Env env, const ID_List id) { return NULL; } -ANN Type prim_ref(const Env env, const Type t, const Type_Decl* td) { - if(GET_FLAG(td, ref) && isa(t, t_object) < 0 && isa(t, t_class) < 0) - ERR_O(td_pos(td), _("primitive types cannot be used as reference (@)...\n")) - return t; -} - ANN Type known_type(const Env env, const Type_Decl* td) { if(!td->xid) return t_undefined; - const Type t = type_decl_resolve(env, td); - return t ? prim_ref(env, t, td) : type_unknown(env, td->xid); -} - -ANN Type known_type_noref(const Env env, const Type_Decl* td) { - if(!td->xid) - return t_undefined; - return type_decl_resolve(env, td) ?: type_unknown(env, td->xid); + return type_decl_resolve(env, td) ?:type_unknown(env, td->xid); } diff --git a/tests/error/arg_prim_ref.gw b/tests/error/arg_prim_ref.gw deleted file mode 100644 index a8191668..00000000 --- a/tests/error/arg_prim_ref.gw +++ /dev/null @@ -1,2 +0,0 @@ -#! [contains] primitive types cannot be used as reference -fun void test(int @i){} diff --git a/tests/error/function_ret_ref_prim.gw b/tests/error/function_ret_ref_prim.gw deleted file mode 100644 index 1dc38819..00000000 --- a/tests/error/function_ret_ref_prim.gw +++ /dev/null @@ -1,2 +0,0 @@ -#! [contains] primitive types cannot be used as reference -fun int@ test(){} diff --git a/tests/error/prim_ref.gw b/tests/error/prim_ref.gw deleted file mode 100644 index 3e4b2930..00000000 --- a/tests/error/prim_ref.gw +++ /dev/null @@ -1,2 +0,0 @@ -#! [contains] primitive types cannot be used as reference -int @i; diff --git a/tests/error/ptr_ref_prim.gw b/tests/error/ptr_ref_prim.gw deleted file mode 100644 index d550dc30..00000000 --- a/tests/error/ptr_ref_prim.gw +++ /dev/null @@ -1,2 +0,0 @@ -#! [contains] primitive types cannot be used as reference -typedef void my_func(int @i){}