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.