Static function usage in constraints

Hello,

I try to use a static function inside a constraint but I see the following error:
*xmsim: F,NWINFUNC (./testbench.sv,31|30): A new() was called by a function in a constraint. The unique id of the failed randomize call is 0.

My code from below can be run here:


class static utils#(type T=int);
  
  static function bit exist(T q[$], T item);
    foreach(q[i])
      if(q[i] == item)
        return 1;
    return 0;
  endfunction
  
endclass

class test;
  rand int aux;
endclass

module tb;
  
  int q[$] = {1};
  string str[$] = {"hello"};
  
  test t1;
  
  initial begin
    $display(utils#(int)::exist(q,0));
    $display(utils#(int)::exist(q,1));
    $display(utils#(string)::exist(str,"hello"));
    
    $display("*****TEST CLASS*****");
    t1 = new();
    void'(t1.randomize with {
      aux == utils#(int)::exist(q,1);
    });
    $display("t1.aux=%0d",t1.aux);
    #10;
    $finish(0);
  end
  
endmodule

Please let me know if it’s possible to use a static function inside a constraint.

Thank you,
Eduard.

In reply to visinescu13:

works fine on Mentor Questa and VCS

I had to remove ‘static’ from class definition,


class  utils#(type T=int);

but, for what you want to achieve, you can put this function in post randomize

In reply to visinescu13:

You’ve run into a tool specific problem, and an LRM issue. Obviously there is no call to new in the function, so the error is a bug. Report that to your tool vendor.

There is not supposed to be a class lifetime in the BNF. That is an LRM bug that got resolved, but the fix was skipped from incorporation.