The this Keyword in SystemVerilog: name clashes, passing yourself, this vs super, and local:: in constraints. Tested on VCS. The Art of Verification

The this Keyword in SystemVerilog: When and Why (Tested)

In short: this is a handle to the object whose method is running. Use it when a local name hides a class member, as in this.tav_len = tav_len;, and when an object needs to hand itself to someone else, as in create("drv", this). It always means the whole object, so a virtual call through this runs the child’s version, while super reaches the parent’s.

You type this in almost every UVM component you write, usually as the last argument of create(). Most of the time nobody explains what it is doing there.

In this lesson we test 8 uses of this in one UVM bench, plus the one-word bug that leaves a constructor quietly broken. I ran it on Synopsys VCS.

Start here: the simplest example

Two classes that differ by one word. Both constructors take an argument with the same name as the member.

// tav_this_simple.sv : the smallest "this" example (UVM 1.2 reporting only)
// The Art of Verification | theartofverification.com
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 30 Nov 2026.
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".

`include "uvm_macros.svh"

class tav_good;
  int tav_len;
  function new(int tav_len);
    this.tav_len = tav_len;                 // this.tav_len is the member
  endfunction
endclass

class tav_bad;
  int tav_len;
  function new(int tav_len);
    tav_len = tav_len;                      // both names mean the argument
  endfunction
endclass

module tav_top;
  import uvm_pkg::*;
  tav_good g;
  tav_bad  b;

  initial begin
    g = new(4);
    b = new(4);
    `uvm_info("TAV_SIMPLE", $sformatf("1  with this    : g.tav_len = %0d", g.tav_len), UVM_NONE)
    `uvm_info("TAV_SIMPLE", $sformatf("2  without this : b.tav_len = %0d", b.tav_len), UVM_NONE)
  end
endmodule

Here is what VCS printed:

UVM_INFO testbench.sv(30) @ 0: reporter [TAV_SIMPLE] 1  with this    : g.tav_len = 4
UVM_INFO testbench.sv(31) @ 0: reporter [TAV_SIMPLE] 2  without this : b.tav_len = 0
  • Line 1: this.tav_len = tav_len; writes the argument into the member, so the member is 4.
  • Line 2: tav_len = tav_len; means the argument on both sides, so the member is never written and stays 0.

The rest of this lesson builds on this. The full bench further down tests the same idea from more angles, with a planted bug.

What you will learn

  • What this points to, and where you can use it.
  • The name clash that makes this necessary in constructors.
  • How to pass or return the current object.
  • Why this inside a parent’s method still reaches the child.
  • The difference between this, super and local::.

Cheat sheet: when to write this

UseCodeWhy
Name clash with an argumentthis.tav_len = tav_len;Without this, both names mean the argument
Pass yourself to another objectsb.tav_register(this);The other object gets a handle to you
Return yourselfreturn this;The caller gets the same object back
Parent of a UVM componentcreate("drv", this)The env becomes the driver’s parent
Parent’s version of a methodsuper.describe()Skips your own override
Caller’s variable in an inline constraintwith { tav_len == local::tav_len; }Plain names mean the item, not the caller

Analogy: this is the word “me”. In a room with two people called Ravi, “Ravi” is unclear, but “me” always means the one speaking.

The name clash

Inside a method, the closest name wins. A constructor argument called tav_len hides the member tav_len, so tav_len = tav_len; copies the argument into itself.

Diagram: inside function new(int tav_len), this.tav_len = tav_len copies the argument (4) into the member, so this.tav_len is 4. With +BUG=1, tav_len = tav_len writes the argument back into itself and this.tav_len stays 0
What VCS returned for p.tav_len: 4 with this, 0 without it.
  • Fix 1: write this.tav_len = tav_len;. This is what UVM code does everywhere.
  • Fix 2: give the argument another name, such as len. Then this is optional, as for tav_id = id; in check 2.

Where you can and cannot use this

PlaceAllowed?
Normal class methods and constructorsYes
Constraints inside the classYes
Static methodsNo: there is no object, so there is no this
Modules, interfaces, programsNo: this belongs to classes

this vs super vs local::

MeansTypical use
thisThe whole current objectName clashes, passing or returning yourself
superThe parent part of the current objectsuper.new(), reusing a parent method in an override
local::The caller’s scope, inside randomize() withComparing an item field with a variable of the same name in the caller

Going further: one bench, 8 checks

  • tav_pkt has a constructor argument named like its member, passes this to a scoreboard, and returns this from a method.
  • tav_err_pkt extends it, to test virtual calls through this and this vs super.
  • tav_env builds a driver with create("drv", this).
  • tav_item is randomized with an inline constraint that uses local::.
  • Planted bug: +BUG=1 drops this from the constructor.

Run it yourself: the same file is on GitHub, with the expected output from both runs.

// tav_this_uvm.sv : the "this" keyword in SystemVerilog, a complete working example (UVM 1.2)
// The Art of Verification | theartofverification.com
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 30 Nov 2026.
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".
// Paste this whole file into testbench.sv and leave design.sv empty.
//
// What is in here:
//   tav_pkt        a class whose constructor argument has the same name as a member
//   tav_err_pkt    a child of it, to show this vs super and virtual dispatch through this
//   tav_sb         a tiny scoreboard that objects register themselves with, using this
//   tav_item       a UVM transaction, for an inline constraint with local::
//   tav_env        builds a driver with create("drv", this)
//   tav_this_test  8 self-checks, each printed with `uvm_info and checked with `uvm_error
//
// Run options:
//   (none)   all 8 checks pass, 0 errors
//   +BUG=1   the tav_pkt constructor writes "tav_len = tav_len;" without this, so check 1 fails

`include "uvm_macros.svh"

package tav_this_pkg;
  import uvm_pkg::*;
  `include "uvm_macros.svh"

  typedef class tav_pkt;

  // ---------------------------------------------------------------
  // A tiny scoreboard: objects hand themselves to it with this
  // ---------------------------------------------------------------
  class tav_sb;
    tav_pkt tav_seen[$];
    function void tav_register(tav_pkt p);
      tav_seen.push_back(p);
    endfunction
  endclass

  // ---------------------------------------------------------------
  // Base class
  // ---------------------------------------------------------------
  class tav_pkt;
    int tav_len;          // same name as the constructor argument
    int tav_id;           // different name from the argument
    static int tav_bug;

    function new(int tav_len, int id, tav_sb sb);
      if (tav_bug == 1)
        tav_len = tav_len;        // BUG: both names mean the argument, the member stays 0
      else
        this.tav_len = tav_len;   // this.tav_len is the member, tav_len is the argument
      tav_id = id;                // no clash, so no this needed
      sb.tav_register(this);      // pass the current object to someone else
    endfunction

    function tav_pkt tav_self();
      return this;                // a method can hand back its own object
    endfunction

    virtual function string vkind();
      return "base";
    endfunction

    function string tav_ask();
      return this.vkind();        // this is the OBJECT, so a child object answers
    endfunction

    virtual function string describe();
      return "base";
    endfunction
  endclass

  // ---------------------------------------------------------------
  // Child class
  // ---------------------------------------------------------------
  class tav_err_pkt extends tav_pkt;
    function new(int tav_len, int id, tav_sb sb);
      super.new(tav_len, id, sb);
    endfunction

    virtual function string vkind();
      return "err";
    endfunction

    virtual function string describe();
      return "child";
    endfunction

    function string tav_both();
      return {this.describe(), "/", super.describe()};   // this: my version, super: the parent's
    endfunction
  endclass

  // ---------------------------------------------------------------
  // UVM pieces
  // ---------------------------------------------------------------
  class tav_item extends uvm_sequence_item;
    `uvm_object_utils(tav_item)
    rand int tav_len;
    constraint c_len { tav_len inside {[1:100]}; }
    function new(string name = "tav_item");
      super.new(name);
    endfunction
  endclass

  class tav_drv extends uvm_component;
    `uvm_component_utils(tav_drv)
    function new(string name, uvm_component parent);
      super.new(name, parent);
    endfunction
  endclass

  class tav_env extends uvm_env;
    `uvm_component_utils(tav_env)
    tav_drv drv;
    function new(string name, uvm_component parent);
      super.new(name, parent);
    endfunction
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      drv = tav_drv::type_id::create("drv", this);   // this = the env, the new driver's parent
    endfunction
  endclass

  // ---------------------------------------------------------------
  // The test
  // ---------------------------------------------------------------
  class tav_this_test extends uvm_test;
    `uvm_component_utils(tav_this_test)

    tav_env env;
    int     tav_pass, tav_fail;

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

    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      void'($value$plusargs("BUG=%d", tav_pkt::tav_bug));
      env = tav_env::type_id::create("env", this);
    endfunction

    function void tav_check(string what, string got, string exp);
      if (got == exp) begin
        tav_pass++;
        `uvm_info("TAV_THIS", $sformatf("PASS %s: %s", what, got), UVM_LOW)
      end
      else begin
        tav_fail++;
        `uvm_error("TAV_THIS", $sformatf("FAIL %s: got %s, expected %s", what, got, exp))
      end
    endfunction

    task run_phase(uvm_phase phase);
      tav_sb      sb = new();
      tav_pkt     p, q, b;
      tav_err_pkt e;
      tav_item    it;
      int         tav_len = 5;    // a local with the same name as the item's field
      phase.raise_objection(this);

      p = new(4, 7, sb);

      // 1. this.tav_len = tav_len: the member gets the argument
      tav_check("1 p.tav_len (name clash, uses this)", $sformatf("%0d", p.tav_len), "4");

      // 2. No clash: tav_id = id works without this
      tav_check("2 p.tav_id (no clash)", $sformatf("%0d", p.tav_id), "7");

      // 3. The constructor passed this to the scoreboard: it holds the same object
      tav_check("3 sb holds p itself (1 = same handle)", $sformatf("%0d", sb.tav_seen[0] == p), "1");

      // 4. A method that returns this gives back the same object
      q = p.tav_self();
      tav_check("4 p.tav_self() == p", $sformatf("%0d", q == p), "1");

      // 5. this inside a base-class method still means the whole object
      e = new(8, 9, sb);
      b = e;
      tav_check("5 b.tav_ask() on a child object", b.tav_ask(), "err");

      // 6. this.method() vs super.method() in the child
      tav_check("6 e.tav_both() (this / super)", e.tav_both(), "child/base");

      // 7. In UVM, create("drv", this) makes the env the parent
      tav_check("7 drv parent / full name",
                $sformatf("%s / %s", env.drv.get_parent().get_full_name(), env.drv.get_full_name()),
                "uvm_test_top.env / uvm_test_top.env.drv");

      // 8. Inline constraint: plain names mean the item, local:: means the caller
      it = tav_item::type_id::create("it");
      if (!it.randomize() with { tav_len == local::tav_len; })
        `uvm_error("TAV_THIS", "randomize() failed")
      tav_check("8 it.tav_len with local::tav_len", $sformatf("%0d", it.tav_len), "5");

      `uvm_info("TAV_THIS", $sformatf("Checks: %0d pass, %0d fail", tav_pass, tav_fail), UVM_NONE)
      phase.drop_objection(this);
    endtask
  endclass

endpackage

module tav_top;
  import uvm_pkg::*;
  import tav_this_pkg::*;
  initial run_test("tav_this_test");
endmodule

How to run it

  1. Open EDA Playground and pick Synopsys VCS with UVM 1.2.
  2. Paste the file into testbench.sv and leave design.sv empty.
  3. Run it once as is, then add +BUG=1 to the run options and run again.

What VCS returned

#CheckResultWhat it proves
1this.tav_len = tav_len4this reaches the hidden member
2tav_id = id7No clash, no this needed
3Scoreboard holds the object passed as this1It is the same handle, not a copy
4p.tav_self() == p1return this gives back the same object
5Base method calls this.vkind() on a child objecterrthis is the object, so the child answers
6Child’s this.describe() / super.describe()child/basesuper skips your override
7create("drv", this) parent / full nameuvm_test_top.env / uvm_test_top.env.drvthis made the env the parent
8with { tav_len == local::tav_len; }5local:: reached the caller’s variable

Result: 8 pass, 0 fail. Here is the log from the clean run.

UVM_INFO @ 0: reporter [RNTST] Running test tav_this_test...
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 1 p.tav_len (name clash, uses this): 4
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 2 p.tav_id (no clash): 7
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 3 sb holds p itself (1 = same handle): 1
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 4 p.tav_self() == p: 1
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 5 b.tav_ask() on a child object: err
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 6 e.tav_both() (this / super): child/base
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 7 drv parent / full name: uvm_test_top.env / uvm_test_top.env.drv
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 8 it.tav_len with local::tav_len: 5
UVM_INFO testbench.sv(195) @ 0: uvm_test_top [TAV_THIS] Checks: 8 pass, 0 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 0: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 0: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   12
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_THIS]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1

The planted bug: one missing word

With +BUG=1, the constructor says tav_len = tav_len;. It compiles, it runs, and nothing in the run log flags the line. Only check 1 fails, with got 0, expected 4.

UVM_INFO @ 0: reporter [RNTST] Running test tav_this_test...
UVM_ERROR testbench.sv(149) @ 0: uvm_test_top [TAV_THIS] FAIL 1 p.tav_len (name clash, uses this): got 0, expected 4
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 2 p.tav_id (no clash): 7
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 3 sb holds p itself (1 = same handle): 1
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 4 p.tav_self() == p: 1
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 5 b.tav_ask() on a child object: err
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 6 e.tav_both() (this / super): child/base
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 7 drv parent / full name: uvm_test_top.env / uvm_test_top.env.drv
UVM_INFO testbench.sv(145) @ 0: uvm_test_top [TAV_THIS] PASS 8 it.tav_len with local::tav_len: 5
UVM_INFO testbench.sv(195) @ 0: uvm_test_top [TAV_THIS] Checks: 7 pass, 1 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 0: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 0: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   11
UVM_WARNING :    0
UVM_ERROR :    1
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_THIS]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1

The lesson: a self-assignment is legal code, so the simulator will not save you. Use this. on every member that shares a name with an argument, or avoid the shared names.

Check 8 in detail: this in the caller, local:: for the caller

In it.randomize() with { ... }, plain names are looked up in the item first. So tav_len == tav_len compares the item’s field with itself, which is always true and constrains nothing.

Writing local::tav_len tells the solver to use the caller’s tav_len, which is 5 in the bench. VCS returned 5.

Common mistakes to avoid

MistakeWhat you seeFix
tav_len = tav_len; in a constructorThe member keeps its default (+BUG=1)this.tav_len = tav_len;
this in a static methodCompile errorMake the method non-static, or pass the object in
create("drv", null) or a missing parentThe driver hangs off the top, not the envPass this from the parent’s build_phase
Same name in caller and item, no local::The inline constraint does nothinglocal::name or a different name
Expecting this in a parent method to mean the parent classThe child’s override runs (check 5)Use super, or make the method non-virtual

How AI helps you master this

  • Find self-assignments: paste your classes and ask for every line that assigns a name to itself.
  • Explain a name lookup: paste a randomize() with block and ask which names belong to the item and which to the caller.
  • Check parents: paste a build_phase and ask which components get the wrong parent.

Warning: a convincing AI answer is not the same as a correct engineering result. Ask an AI tool whether tav_len = tav_len; sets the member and it may say yes, so run the code.

Interview questions on this

  • What does this refer to? The object whose method is running.
  • Why is this needed in this.x = x;? The argument x hides the member, so this is needed to reach the member.
  • Can you use this in a static method? No. A static method has no object.
  • What is the difference between this and super? this is the whole object. super reaches the parent’s version of a member or method.
  • Why do UVM components pass this to create()? It sets the new component’s parent, which builds the hierarchy and its full path name.

More practice: SystemVerilog interview questions.

Practice challenge

  1. Run the bench and confirm 8 pass, 0 fail.
  2. Run with +BUG=1 and explain why the member is 0.
  3. Remove local:: from check 8. Predict what it.tav_len can be, then run it a few times with different seeds.
  4. Bonus: make vkind() non-virtual in tav_pkt. What does check 5 return now, and why?

FAQ

What is the this keyword in SystemVerilog? A built-in handle to the current object, usable inside non-static class methods and constraints.

When do I need to use this? When a local name, usually an argument, hides a member, and when you pass or return the current object.

What is the difference between this and super? this is the whole object, so virtual calls through it run the child’s version. super calls the parent’s version.

Can I use this in a static method? No. Static methods belong to the class, not to an object.

Does this affect performance? No. this.x and x reach the same member when there is no clash.

How is this used in UVM? Mostly as the parent argument, as in create("drv", this), and in raise_objection(this) to say which component raised it.

References

  • IEEE 1800-2017, SystemVerilog standard: section 8.11 (this), section 8.15 (super), and section 18.7.1 (local:: in inline constraints).

Keep learning