Usage of local:: keyword

Consider this code:

virtual class parent extends parent_base

constraint parent_c{

x inside {[1:24]}
}

task body();
child child_h

if(!child_h.randomize() with {
x == local::x}
`uvm_fatal(get_name(), "Failed to randomize");
}
class child extends child_base;

class parent_base extends child_base;

rand bit x;

While running a test, my constraints fail because of the signature:
local bit x = 0 → but x inside {[1:24}]

Why does local::x take the value 0?

Please post a complete example which demonstrates you issue/question.

Also, you use the terms ‘child’ and ‘parent’, which aren’t correct. A child class is a class which is instantiated in a parent class.

You want to use the terms base and extended when discussing classes that extend a class and add additional variables/functions/tasks/etc.

Actually, the use of parent and child might be correct here.

But you’ve only shown one declaration of the variable x in the parent_base class, which is what local::x would refer to. There is no x in the child or child_base class shown.

Also, you are calling child_h.randomize(); the parent_c constraint is not active.

Yes, the rand variable x only exists in parent base class.

Wondering, why while calling child_h.randomize(), the constraint is not active?

Would that mean the constraint of parent class would only be active for member of parent class?

So the constraint x == local::x is always true because both sides are referencing the same variable.

Constraints are only active on the object for which the randomize() call is made on. If, instead, you had called this.randomize() and made child_h a rand variable, then the parent_c constraint would have been active.

If I write:

if(!child_h.randomize() with {
x == x}
`uvm_fatal(get_name(), “Failed to randomize”);
}

Does that mean, LHS ‘x’ is corresponding to child_h.x and RHS ‘x’ is the rand variable declared in parent_base class?

In that case, if I have constraints in parent_base class, would that apply to RHS ‘x’?

No. The search rules for identifiers are independent of where they appear the constraint expression. x ==x resolves to child_h.x == child_h.x