# Unable to access class properties in a UVM factory overriden class

**URL:** <https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344>\
**Category:** UVM\
**Tags:** uvm\_set\_inst\_override, UVM, UVM-Factory-Registration, Bad-handle, connect-sequencer\
**Created:** [April 15, 2018, 10:41pm UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344 "2018-04-15T22:41:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterjin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Post date:** [April 15, 2018, 10:41pm UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/1 "2018-04-15T22:41:26Z")

</div>

Hi,

In my testbench, I have a class called nspi\_master\_agent and a parameterized class nspi\_master\_agent\_param#(SOME\_PARAMS\_HERE) which is derived from nspi\_master\_agent. And this nspi\_master\_agent has a uvm\_sequencer in it.

```auto
typedef uvm_sequencer #(payload_data) nspi_sequencer;
 
class nspi_master_agent extends uvm_agent;
  ...
  nspi_sequencer m_seqr;
  ...
  `uvm_component_utils(nspi_master_agent)
  ...
endclass

class nspi_master_agent_param#(VARIOUS_PARAMETERS_HERE) extends nspi_master_agent;
  nspi_sequencer m_seqr;
  ...
  `uvm_component_param_utils(nspi_master_agent_param#(VARIOUS_PARAMETERS_HERE))
  ...
  virtual function void build_phase(uvm_phase phase);
     super.build_phase(phase);
     ...
     m_seqr = nspi_sequencer::type_id::create("m_seqr", this);
     ...
  endfunction
  ...
endclass

```

In my uvm\_test class, I overrode nspi\_master\_agent with nspi\_master\_agent\_param class

```auto
for (int i=0;i!=NUM_ETH_PORT; i++) begin 
      set_inst_override_by_type(($sformatf("ne_buf_env.ne_buf_nspi_agt_ne_wrch[%0d]", i)), nspi_master_agent::get_type(), nspi_master_agent_param#(PASSING_PARAM_VALUE)::get_type() );  
end

```

In my uvm\_env class, I created several nspi\_master\_agent objects

```auto
for (int i=0; i!=NUM_ETH_PORT; i++) begin
      ne_buf_nspi_agt_ne_wrch[i] = nspi_master_agent::type_id::create($sformatf("ne_buf_nspi_agt_ne_wrch[%0d]", i), this);
end

```

Also in my test class, I would like to pass the sequencer handle inside a nspi\_master\_agent object to a uvm\_sequencer\_base handle inside my test class.

```auto
virtual task main_phase(uvm_phase phase);
uvm_sequencer_base nspi_msqr;
...
nspi_msqr=ne_buf_env.ne_buf_nspi_agt_ne_wrch[0].m_seqr;
...
endtask

```

However, after running the simulation, the nspi\_msqr will get a null value, and after some debug, I found that  
“ne\_buf\_env.ne\_buf\_nspi\_agt\_ne\_wrch[0]” is actually referring to the original nspi\_master\_agent which never got created (I tried to access a property which only exists in the derived nspi\_master\_agent\_param class and VCS give me a compilation error saying that property doesn’t exist in ne\_buf\_env.ne\_buf\_nspi\_agt\_ne\_wrch[0] object)

Thus I wonder why am I referring to the original class in

```auto
nspi_msqr=ne_buf_env.ne_buf_nspi_agt_ne_wrch[0].m_seqr;

```

And how should I correcty pass the m\_seqr handle to my test class?

Thanks so much in advance!!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 15, 2018, 11:10pm UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/2 "2018-04-15T23:10:18Z")

</div>

_In reply to [peterjin](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344):_

At least one of your problems is you declared m\_seqr in both nspi\_master\_agent and nspi\_master\_agent\_param. You should never redeclare a variable with the same name in both classes.

---

<div class="post-metadata">

**Author:** ![peterjin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Post date:** [April 16, 2018, 3:35am UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/3 "2018-04-16T03:35:24Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/2):_

Hi Dave,

Thanks for your reply!

Actually, that agent is our company’s legacy code. And they used to launch the sequence by setting sequencer’s default\_sequence in the following fashion: (part of my job is to convert the sequence launching method from “default\_sequence associating” to using virtual sequence)

```auto
for (int i=0; i!=NUM_ETH_PORT; i++) begin 
      uvm_config_db #(uvm_object_wrapper)::set(this, $sformatf("ne_buf_nspi_agt_ne_wrch[%0d].m_seqr.main_phase", i), "default_sequence", nebuf_nspi_sequence::get_type());
end

```

I wonder why in the above code (in enviroment component), .m\_seqr is correctly referred to the m\_seqr inside nspi\_master\_agent\_param class?

---

<div class="post-metadata">

**Author:** ![mayurkubavat](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mayurkubavat](https://verificationacademy.com/forums/u/mayurkubavat)\
**Post date:** [April 16, 2018, 9:36am UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/4 "2018-04-16T09:36:11Z")

</div>

_In reply to [peterjin](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/3):_

Use access method which makes use of polymorphism to get sequencer according to objects you create.

Even if you have override and create extended class objects, parent handle still remains same. And using parent handle you can only access parent properties or functions and extended class functions if virtual.

Access m\_seqr like this,

```verilog
class A;
  my_seq m_seqr; // Class A property
  //Create object for m_seqr
  //..

  virtual function my_seq getSeq();
    return m_seqr;
  endfunction
endclass

class B extends A;
  my_seq m_seqr; // Class B property
  //Create object for m_seqr
  //..

  function my_seq getSeq();
    return m_seqr;
  endfunction
endclass

```

Issue is not with declaring same handle name m\_seqr in both the class. But it’s how inheritance works when using parent=child handle assignments.

---

<div class="post-metadata">

**Author:** ![peterjin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Post date:** [April 16, 2018, 8:06pm UTC](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/5 "2018-04-16T20:06:57Z")

</div>

_In reply to [MayurKubavat](https://verificationacademy.com/forums/t/unable-to-access-class-properties-in-a-uvm-factory-overriden-class/34344/4):_

That solves the problem, thanks so much for your help!

Hao
