Can we use factory type override for a sub-class that has extra methods?

Hi,
I got an compile error during elaboration, when I’ve tried to override subclass type that has extra methods. Is there any way that I can use factory for the situation or better way?
(Adding every extra methods of sub classes to the base classe looks not a goot choice.)

Let me share my codes and error


class base_agent extends uvm_agent;

  `mb_vip_reporter_utils
  `uvm_component_utils(base_agent)

  function new(string name, uvm_component parent);
    super.new(name, parent);
    this.rptr = new(name);
  endfunction

  virtual function void build_phase(uvm_phase phase);
	  super.build_phase(phase);
  endfunction

  virtual function void general();
    this.info_w_full_name("base_agent.general");
  endfunction

  // Need to add this code parts to avoid compile error
  // virtual function void specific();
  //   this.info_w_full_name("base_agent.specific");
  // endfunction

endclass:base_agent

class base_test extends uvm_test;

  base_agent  agent;

  `mb_vip_reporter_utils
  `uvm_component_utils(base_test)

  function new(string name, uvm_component parent=null);
    super.new(name, parent);
    this.rptr = new(name);
  endfunction

  virtual function void build_phase(uvm_phase phase);
	  super.build_phase(phase);

    this.agent = base_agent::type_id::create("agent", this);
  endfunction


  virtual task run_phase(uvm_phase phase);                                                            
    this.agent.general();
  endtask

endclass:base_test


class extended_agent extends base_agent;

  `uvm_component_utils(extended_agent)

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);
	  super.build_phase(phase);
  endfunction

  virtual function void general();
    this.info_w_full_name("extended_agent.general");
  endfunction

  virtual function void specific();
    this.info_w_full_name("extended_agent.specific");
  endfunction

endclass:extended_agent


class extended_test extends base_test;

  `uvm_component_utils(extended_test)

    static uvm_factory factory = uvm_factory::get();

  function new(string name="extended_test", uvm_component parent=null);
    super.new(name, parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);
	  super.build_phase(phase);
    factory.set_type_override_by_type(base_agent::get_type(), extended_agent::get_type());
    factory.print();
  endfunction

  virtual task run_phase(uvm_phase phase);                                                            
    super.run_phase(phase);
    this.agent.specific();  // <----------- Compile error when base_agent  does not include the specific method.
  endtask

endclass:extended_test


[COMPILE ERROR]
Error-[MFNF] Member not found
/home/sungmin.hong/grepo/infra_w0//viplib/mb_vip/include/study.svh, 167
"this.agent."
  Could not find member 'specific' in class 'base_agent', at 
  "/home/sungmin.hong/grepo/infra_w0//viplib/mb_vip/include/study.svh", 8.

In reply to Sungmin_Hong:

Another issue in here,
After I added specific method into “base_agent”, I could compile it, but the result is not what I expected. As factory said extended_agent is overrided as agent, it have to show “extended_agent.general, extended_agent.specific” but it was about base_agent.

Type Overrides:

  Requested Type  Override Type  
  --------------  ---------------
  base_agent      extended_agent


UVM_INFO @ 0: agent [] [agent] base_agent.general
UVM_INFO @ 0: agent [] [agent] base_agent.specific

In reply to Sungmin_Hong:

The override is registered after creating base_agent type in build_phase() of base_test .

Hence agent is created of type ’ base_agent ’ .

Try the following ::


virtual function void build_phase(uvm_phase phase);	  
    factory.set_type_override_by_type(base_agent::get_type(), extended_agent::get_type());

    super.build_phase(phase);  //  Called  after  Registering  Override  !!
    factory.print();
  endfunction