Illegal assignmenet to component from type string

Hello Forum,

Could you please help in debugging the error:

In the very simple monitor class, the file is given below, i am getting the following error at line number 24.

class monitor extends uvm_monitor;
 `uvm_component_utils(monitor)
  
  virtual intf m_vi;;
 
  uvm_analysis_port#(trans)mntr_ap;

 function new(string name = "monitor", uvm_component parent);
 super.new(name,parent);
 endfunction
 
 function void build_phase(uvm_phase phase);
 super.build_phase(phase);
 void'(uvm_config_db#(virtual intf)::get(this, "", "intf", m_vi)); 
 mntr_ap = new("mntr_ap", this);
 endfunction

 task run_phase(uvm_phase phase);
 forever
begin
   trans tr;
  @m_vi.slave_cb;
  if(m_vi.slave_cb.flavor != trans::NO_FLAVOR)begin
  tr = trans::type_id::create(.name("tr"), .contxt(get_full_name())); //HERE IS THE ERROR.
  tr.flavor     = trans::flavor_e'(m_vi.slave_cb.flavor);
  tr.color      = trans::color_e'(m_vi.slave_cb.color);
  tr.sugar_free = m_vi.slave_cb.sugar_free;
  tr.sour       = m_vi.slave_cb.sour;
  @m_vi.master_cb;
  tr.taste      = trans::taste_e'(m_vi.master_cb.taste);
  mntr_ap.write(tr);
  end
end 
 endtask
endclass

The error is given below:

monitor.sv(24): Illegal assignment to class mtiUvm.uvm_pkg::uvm_component from type String

I tried to resolve it by removing the get_full_name(), and then also same error is there.
Could you please help me in locating the issue.

In reply to bhavik.pipaliya:

The second argument to the create function requires a component context. Please use “this” as the component contxt (without the double quotes)

I very strongly do not recommend using “new” as you lose the factory override capability (a key ingredient in UVM testbenches)

In reply to sunils:

the command for creating your Transaction object has only 1 Argument of type string. The string has to be the same as the object is named.
tr = trans::type_id::create(“tr”);

In reply to logie:

Hi Bhavik,

It is giving the same error, as before.

-Sunil

Hi Bhavik/Chr,

In the monitor, the error is resolved with the following two changes:

  1. I changed the new function in transaction class to the following:
function new(string name = "trans"); // earlier it was "" only.
   super.new(name);
   endfunction
  1. Putting "
this

" in

type_id::create()

function, called in the monitor.sv class.

Now the same error is there in test.sv class. I am not able to resolve it with above hack.
Could you please help me in understanding that my above hack is wrong or not. I think my above hack is making sense, But it is not working in test.sv class. Please help.

-Sunil.

Hi sunils,

Please attached your snapshot of “test.sv”, so i can help you correct way.

In reply to bhavik.pipaliya:

Hi Bhavik,

Here is the test.sv file:

class test extends uvm_test;
 `uvm_component_utils(test)

 environment env;

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

function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      begin
         configuration cfg;
 
         cfg = new;
         assert(cfg.randomize());
         uvm_config_db#(configuration)::set(this, "*", "config", cfg);
	 trans::type_id::set_type_override(two_seq::get_type());
         env = environment::type_id::create("env", this);
      end
   endfunction


task run_phase(uvm_phase phase);
      three_seq seq;
 
      phase.raise_objection(this);
      seq = three_seq::type_id::create("seq",this);//,get_full_name()); //Here is the error.
      assert(seq.randomize());
      `uvm_info("test", { "\n", seq.sprint() }, UVM_LOW) seq.start(env.at.seqr);
      #10ns ;
      phase.drop_objection(this);
   endtask
   
endclass

Hi Sunils,

I think you made same mistake in “three_seq.sv” of new() constuctor.

In reply to bhavik.pipaliya:

Hi Bhavik,

Here is the three_seq.sv file:

class three_seq extends uvm_sequence#(trans);
   rand int unsigned num_jelly_bean_flavors; // knob
 
   constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors inside { [2:3] }; }
 
   function new(string name = "");
      super.new(name);
   endfunction: new
 
   task body();
      two_seq jb_seq;
      repeat (num_jelly_bean_flavors) begin
         jb_seq = two_seq::type_id::create("jb_seq",get_full_name());
         assert(jb_seq.randomize());
         jb_seq.start(.sequencer(m_sequencer), .parent_sequence(this));
      end
   endtask: body
 
   `uvm_object_utils_begin(three_seq)
      `uvm_field_int(num_jelly_bean_flavors, UVM_ALL_ON)
   `uvm_object_utils_end
endclass: three_seq

In the trans.sv, one_seq, two_seq, and three_seq files, the new constructor have only the “” for string.
Could you please relate something workable.
-Sunils

In reply to sunils:

Please note as said above, the create::id method for an object has ONLY 1 Argument. This is a string with the Name of this object.