VLSI DV Interview Puzzles · All levels

Missing super.new with Required Base Args

Why does this class fail before simulation even starts, and what exact fix is required?

Puzzle

Difficulty: Medium · Puzzle 2 of 6 · Topic: Virtual Method Puzzles

Why does this class fail before simulation even starts, and what exact fix is required?

Code

systemverilog
class base_cfg;
  int id;
  function new(int id);
    this.id = id;
  endfunction
endclass

class ext_cfg extends base_cfg;
  function new();
    // no super.new call
  endfunction
endclass

Hint

Constructors are not optional in inheritance when base has required parameters.

Step-by-step solution

diagram
1) `base_cfg` has no zero-argument constructor; it requires `id`.
2) `ext_cfg::new` must call `super.new(<id>)` as the first statement.
3) Without it, compilation/elaboration fails due to unsatisfied base constructor call.

Answer

Answer: It is illegal because base constructor needs an argument and `ext_cfg` never calls `super.new(id)`.

Why candidates get it wrong

Candidates coming from other languages assume base default constructor is auto-synthesized.

Interviewer follow-up

How would you thread this constructor argument from UVM factory `create` path in components?

Related topics