# How does set\_inst\_override\_by\_type work?

**URL:** <https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878>\
**Category:** UVM\
**Tags:** UVM, set\_inst\_override, factory\
**Created:** [June 1, 2016, 4:28am UTC](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878 "2016-06-01T04:28:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlsxdx](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@mlsxdx](https://verificationacademy.com/forums/u/mlsxdx)\
**Post date:** [June 1, 2016, 4:28am UTC](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878/1 "2016-06-01T04:28:13Z")

</div>

Hi,

Can somebody help me to understand how factory.set\_inst\_override\_by\_type work when the override class contains an original class object?

A original\_type  
B override\_type, which contains A object

When use B override A, should I expect the A\_obj also get override?  
I tried it on irun, it gets stuck?

```verilog
module tb;
import uvm_pkg::*; 
`include "uvm_macros.svh"
   
class A extends uvm_object;
   rand bit[7:0] pkt_len;
   `uvm_object_utils_begin(A)
      `uvm_field_int(pkt_len, UVM_ALL_ON)
   `uvm_object_utils_end
   
   function new(string name="A");
      super.new(name);
   endfunction // new
endclass // A

typedef enum {ETH, IPV4} pkt_type_e;

class B extends A;
   rand pkt_type_e pkt_type;
   A A_obj;
   
   `uvm_object_utils_begin(B)
      `uvm_field_enum(pkt_type_e, pkt_type, UVM_ALL_ON)
      `uvm_field_object(A_obj, UVM_ALL_ON)
   `uvm_object_utils_end
   
   function new(string name="B");
      super.new(name);
      A_obj = A::type_id::create("A");
   endfunction // new
endclass // B

class test1 extends uvm_test;
    A A1;
    B B1;

   `uvm_component_utils(test1)
   function new(string name="test1", uvm_component parent);
      super.new(name, parent);
   endfunction // new

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

      A::type_id::set_inst_override(B::get_type(), "*");
      A1 = A::type_id::create("A1");
      A1.print();

   endfunction // build_phase
endclass // test1
   
initial run_test("test1");
endmodule

```

---

<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:** [June 1, 2016, 5:50am UTC](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878/2 "2016-06-01T05:50:45Z")

</div>

_In reply to [mlsxdx](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878):_

You are getting into an infinite loop because you are using the wildcard “\*” as the instance name, which is the same as overriding all A class types with B. Then you are creating a B object which contains a B object, which contains a B object.

With class derived from uvm\_object, the instance name is just the simple name of the object, so if you change your override to

```verilog
      A::type_id::set_inst_override(B::get_type(), "A1");

```

It should work that way you expect it to.

---

<div class="post-metadata">

**Author:** ![mlsxdx](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@mlsxdx](https://verificationacademy.com/forums/u/mlsxdx)\
**Post date:** [June 5, 2016, 8:59pm UTC](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878/3 "2016-06-05T20:59:43Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-does-set-inst-override-by-type-work/31878/2):_

Thanks Dave. It works as you said.
