From fd27160c6424935f151d23eee11af4085e7a0732 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 23 Oct 2020 11:31:47 +0200 Subject: [PATCH] :bug: Prevent inheritance from abstract type --- src/parse/scan0.c | 9 ++++++++- tests/error/find_type.gw | 2 +- tests/error/no_inherit.gw | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/error/no_inherit.gw diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 4cfecfdd..6047da5f 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -322,6 +322,13 @@ ANN static Type get_parent_base(const Env env, Type_Decl *td) { return t; } +ANN static Type check_abstract(const Env env, Type_Decl *td) { + DECL_OO(const Type, t, = known_type(env, td)) + if(!GET_FLAG(t, abstract)) // could be final + return t; + ERR_O(td_pos(td), _("can't inherit from abstract parent class '%s'\n."), t->name); +} + ANN static Type get_parent(const Env env, const Class_Def cdef) { if(GET_FLAG(cdef, struct)) return env->gwion->type[et_compound]; @@ -331,7 +338,7 @@ ANN static Type get_parent(const Env env, const Class_Def cdef) { return get_parent_base(env, cdef->base.ext); if(cdef->base.tmpl) template_push_types(env, cdef->base.tmpl); - const Type t = known_type(env, cdef->base.ext); + const Type t = check_abstract(env, cdef->base.ext); if(cdef->base.tmpl) nspc_pop_type(env->gwion->mp, env->curr); return t ?: (Type)GW_ERROR; diff --git a/tests/error/find_type.gw b/tests/error/find_type.gw index b587462f..b6f87553 100644 --- a/tests/error/find_type.gw +++ b/tests/error/find_type.gw @@ -1,4 +1,4 @@ #! [contains] unknown type -class C extends UGen { +class C extends UserUGen { var D d; } diff --git a/tests/error/no_inherit.gw b/tests/error/no_inherit.gw new file mode 100644 index 00000000..d37f6278 --- /dev/null +++ b/tests/error/no_inherit.gw @@ -0,0 +1,7 @@ +#! [contains] can't inherit +class C extends TypedFork:[int] { + +} + +var C c; +c.exit(); -- 2.43.0