Factory override non-parameterized class with parameterized one

Hi,

I have a question about the UVM factory overriding with parameterization. More precisely, I am trying to the the following “trick” (simplified example):


// Declare base component which is instantiated and created somewhere in my testbench hierarchy
class my_base_component extends uvm_component;
  `uvm_component_utils(my_base_component)
  ...

// Derive new type which has one additional class parameter
class my_derived_component #(parameter int PARAM = 1) extends my_base_component;
  `uvm_component_param_utils(my_derived_component)
  ...

// Somewhere in test (before super.build_phase call), override the my_base_component type with the my_derived_component type, but tune the parameter to be 6.
my_base_component::type_id::set_type_override(my_derived_component#(6)::get_type(), 1);

But, when I have placed the debug print in the my_derived_component to print out PARAM value, I can see from the log that PARAM remains “1” although I tried to give value of “6” for it the factory override call.

Just wonder whether I should be able to give the another parameter value for the class specification in the factory override or not?

Thanks!

-ilia

In reply to ilia:
The problem is with your use of the `uvm_component_param_utils macro. You need to include the parameters in the reference.

  `uvm_component_utils(my_base_component#(PARAM))

It is a good idea to leave the default parameter setting out of the class declaration. Then you would have gotten a compiler error.

class my_derived_component #(parameter int PARAM) extends my_base_component;
  `uvm_component_param_utils(my_derived_component) // would have generated a compiler error.

It is unfortunate that SystemVerilog uses my_derived_component not to mean the generic template class, but instead to mean my_derived_component#(), which is a class specialization using the defaults for all parameters.

By removing the default parameter assignments, that forces the user to supply an override with each class reference.

In reply to dave_59:

Thank you Dave! Now I understand why you need take the factory registration of the parameterized class very seriously.