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);
}
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)
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));
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;
}
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);
}
+++ /dev/null
-#! [contains] primitive types cannot be used as reference
-fun void test(int @i){}
+++ /dev/null
-#! [contains] primitive types cannot be used as reference
-fun int@ test(){}
+++ /dev/null
-#! [contains] primitive types cannot be used as reference
-int @i;
+++ /dev/null
-#! [contains] primitive types cannot be used as reference
-typedef void my_func(int @i){}