Make sure chained constructor is called when using `extends`

Currently when neither an explicit constructor is specified nor any
properties are present in the class that will create an implicit
constructor there will be no constructor for the class.

As a result a class that specifies the arguments for the base class
constructor as part of the `extends` clause will not have the base
constructor called with the right arguments.

E.g.
```
class C;
  function new(int a);
  endfunction
endclass

class D extends C(10);
endclass
```

To avoid this make sure that an implicit constructor is created when
passing arguments through the `extends` clause.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-08-01 04:48:53 -07:00
parent 6ea01cbf7f
commit c512faa967
1 changed files with 5 additions and 2 deletions

View File

@ -147,8 +147,11 @@ void pform_end_class_declaration(const struct vlltype&loc)
ivl_assert(loc, pform_cur_class);
// If there were initializer statements, then collect them
// into an implicit constructor function.
if (! pform_cur_class->type->initialize.empty()) {
// into an implicit constructor function. Also make sure that an
// explicit constructor exists if base class constructor arguments are
// specified, so that the base class constructor will be called.
if (!pform_cur_class->type->initialize.empty() ||
!pform_cur_class->type->base_args.empty()) {
PFunction*func = pform_push_function_scope(loc, "new@", LexicalScope::AUTOMATIC);
func->set_ports(0);
pform_set_constructor_return(func);