Skip to content

Request for new warning for variable 'overloading' in var.randomize() calls #1533

@jcurtiss8086

Description

@jcurtiss8086

A common bug that appears in testbench code involves randomizing an object from a scope where a variable exists with the same name as a variable in the object that is being randomized. Using the local:: prefix tells the compiler to use the local-scope variable, but when the coder forgets to use the local:: prefix, then very subtle bugs are introduced that are difficult to catch via visual-inspection/code-reviews.

In the example below, the code should have used x == local::y. A warning that can flag the name-overloading for y in this instance would help reduce the need for a lot of manual code-reviews and prevent a lot of coding bugs earlier in the process.

class A;
    rand int x;
    rand int y;
endclass

class B;

    function f();
        A a;
        int y = 5;
        a.randomize() with {
            x == y;   // Warning here that y is defined in both locally and in 'a' so 'a.y' is being used?
        };
    endfunction

endclass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions