Function call in System Verilog constraint

In reply to sunilkakkar:

I have a constraint like this:
constraint constraint_len {
soft len == calculate_len(x);
}
x is itself a local constrained random variable.
The function “calculate_len” seems to calculate the correct length and returns it, but “len” is always coming up to be a 1.
Any hints on what may be going wrong?

Please post more code to see what is real problem. You are using soft contraint, please make sure len variable aren’t being contrainted somewhere-else in child class.