From 005fe2094ac1ed3465bbdf3efaf28d49e57ce84a Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 19 Jul 2019 17:30:49 +0200 Subject: [PATCH] :bug:\ Fix\ already\ declared, tl2str --- src/parse/scan1.c | 2 +- src/parse/type_decl.c | 46 ++-------------------------- tests/nonnull/nonnull2nullable.gw | 1 - tests/nonnull/normal_cast_nonnull.gw | 1 - tests/nonnull/null_impl_nonnull.gw | 2 +- tests/nonnull/ref_at_nonnull.gw | 2 +- tests/nonnull/ref_impl_nonnull.gw | 2 +- 7 files changed, 6 insertions(+), 50 deletions(-) diff --git a/src/parse/scan1.c b/src/parse/scan1.c index f64d1401..1c219586 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -88,7 +88,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)) Type t = decl->type; const Value former = nspc_lookup_value0(env->curr, var->xid); - if(former && !(decl->td->exp || decl->td->xid)&& + if(former /* && !(decl->td->exp || decl->td->xid) */&& (!env->class_def || !(GET_FLAG(env->class_def, template) || GET_FLAG(env->class_def, scan1)))) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 5fa7f90c..cd75753d 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -41,59 +41,17 @@ struct td_info { GwText text; }; -ANEW ANN static m_str td2str(const Env env, const Type_Decl* td); ANN static m_bool td_info_run(const Env env, struct td_info* info) { Type_List tl = info->tl; do { - DECL_OB(m_str, name, = td2str(env, tl->td)) - text_add(&info->text, name); - free_mstr(env->gwion->mp, name); + DECL_OB(const Type, t, = known_type(env, tl->td)) + text_add(&info->text, t->name); if(tl->next) text_add(&info->text, ","); } while((tl = tl->next)); return GW_OK; } -ANN static ssize_t id_list_len2(const Nspc nspc, ID_List l) { - ssize_t len = 0; - do { - DECL_OB(const Type, t, = nspc_lookup_type1(nspc, l->xid)) - len += strlen(t->name); - } while((l = l->next) && ++len); - return len + 1; -} - -ANN static void type_path2(const Nspc nspc, const m_str str, ID_List l) { - m_str s = str; - do { - const Type t = nspc_lookup_type1(nspc, l->xid); - const m_str name = t->name; - strcpy(s, name); - s += strlen(name); - if(l->next) - strcpy(s++, "."); - } - while((l = l->next)); -} - -ANEW ANN static m_str td2str(const Env env, const Type_Decl* td) { - m_uint depth = td->array ? td->array->depth : 0; - DECL_BO(const ssize_t, len, = id_list_len2(env->curr, td->xid) + depth * 2); - const size_t cap = round2szint(len); - struct td_info info = { td->types, - { (m_str)mp_malloc2(env->gwion->mp, cap), cap, len, env->gwion->mp } - }; - type_path2(env->curr, info.text.str, td->xid); - while(depth--) { text_add(&info.text, "[]"); } - Type_List tl = td->types; - if(tl) { - text_add(&info.text, "<"); - CHECK_BO(td_info_run(env, &info)) - text_add(&info.text, ">"); - } - return info.text.str; -} - ANEW ANN m_str tl2str(const Env env, Type_List tl) { struct td_info info = { .tl=tl, { .mp=env->gwion->mp} }; CHECK_BO(td_info_run(env, &info)) diff --git a/tests/nonnull/nonnull2nullable.gw b/tests/nonnull/nonnull2nullable.gw index bed60ffe..e1561f1d 100644 --- a/tests/nonnull/nonnull2nullable.gw +++ b/tests/nonnull/nonnull2nullable.gw @@ -1,2 +1 @@ -#! [contains] can't assign Object ! o @=> Object @p; diff --git a/tests/nonnull/normal_cast_nonnull.gw b/tests/nonnull/normal_cast_nonnull.gw index da1bbc75..9fb6fb4b 100644 --- a/tests/nonnull/normal_cast_nonnull.gw +++ b/tests/nonnull/normal_cast_nonnull.gw @@ -1,2 +1 @@ -#! [contains] can't cast new Object $ Object!; diff --git a/tests/nonnull/null_impl_nonnull.gw b/tests/nonnull/null_impl_nonnull.gw index b9628cde..92a9010f 100644 --- a/tests/nonnull/null_impl_nonnull.gw +++ b/tests/nonnull/null_impl_nonnull.gw @@ -1,3 +1,3 @@ -#! [contains] NullPtrException +#! [contains] can't implicitly cast fun void test(Object !o) { <<< o >>>; } null => test; diff --git a/tests/nonnull/ref_at_nonnull.gw b/tests/nonnull/ref_at_nonnull.gw index 55f5c447..0c8738e3 100644 --- a/tests/nonnull/ref_at_nonnull.gw +++ b/tests/nonnull/ref_at_nonnull.gw @@ -1,2 +1,2 @@ #! [contains] NullPtrException -Object @o @=> Object !o; +Object @o @=> Object !p; diff --git a/tests/nonnull/ref_impl_nonnull.gw b/tests/nonnull/ref_impl_nonnull.gw index ea07c0b4..35a7cd7c 100644 --- a/tests/nonnull/ref_impl_nonnull.gw +++ b/tests/nonnull/ref_impl_nonnull.gw @@ -1,3 +1,3 @@ -#! [contains] can't implicitly cast +#! [contains] NullPtrException fun void test(Object !o) { <<< o >>>; } Object @o => test; -- 2.43.0