How can this property be changed to remove the error (VERI-1537)? - system-verilog

I'm trying to write a property as:
property seq_op_1;
logic [PW_WIDTH-1:0] mk;
((~|a_valid && !b_valid) ##1
((b_valid && b_ready && (b_len == 4'h0)),mk=b_mk) ##[1:MAX_COUNT]
(c_valid && c_ready && (c_mk == mk) && c_last));
endproperty
cover_seq_op_1 : cover property (seq_op_1);
However, when the running analysis/elaboration I get the following error:
VERI-1537: local variable 'mk' is referenced in expression where it does not flow.
What am I doing wrong here?
I could not come up with a solution to try.

Related

Linq where clause with nullable parameters

I'm trying to do a linq query which might have nullable params.
This is my linq call
listOfControlsVM = db.Controls.Where((status == null || s.Status.Description == status) && (impact == null || s.Impact == impact)).ToList();
Now either status or impact can be nullable params (I have two more but I removed them from the example). With the approach I have the query doesn't return the correct set of results.
I want to know if there is other better approach to work with nullable params in linq. For example if status or impact have value include them in the conditions, otherwise skip them.
There is a HasValue to check null value on nullable variable instead of null.
listOfControlsVM = db.Controls.Where((!status.HasValue || s.Status.Description == status) && (!impact.HasValue || s.Impact == impact)).ToList();
I hope this will help you out :)

Swift User Creation Not Detecting UIText Length

working on user creation. Pretty simple idea, the email can't be nil or empty, password and confirm password have to be equal to be each other, and password has to be over 6 characters. For whatever reason, this last condition is always passing true. Because of this, users are able to register with a 1 letter or number password. Why would this be happening?
else if(emailTxt.text != "" && passwordTxt.text == confirmPassTxt.text && passwordTxt.text?.characters.count > 6){}
Also, something interesting, I can obviously compare the values because this code to get an password mismatch works perfectly fine.
else if(emailTxt.text != "" && passwordTxt.text != confirmPassTxt.text)
This will return true or false correctly. So the problems come from counting the characters, but I just can't see it right now. Simple mistake?
Interesting way I solved this. Because I never gave an option for Swift to choose if the password WASN'T above 6 characters, it just assumed it was? Not sure why, but adding another condition like this worked.
lse if(emailTxt.text != "" && passwordTxt.text == confirmPassTxt.text && passwordTxt.text?.characters.count < 6 && confirmPassTxt.text?.characters.count < 6){
As you can see it is essentially the same except I changed the > symbols to <. Working perfectly fine now

How to use IN Operator inside Where Condition in Linq

I need a help to how to use IN Operator in linq ,
Here is my Code:
achieved =grouped.Key.SMCode=="HETAL1"?
grouped.AsEnumerable().Where(x => (x.SalesManCode=="HETAL1"||x.SalesManCode=="BAIJU") &&
x.OrderType == "Sales Invoice" && x.IsFromService==true).Sum(m => m.OrderValue):0
Here i need the value for both Salesmancode baiju and hetal1 ,but now i got value only for hetal1
i dont know , how to use IN operator in linq
pls help me to get the values of both salesmancode
Please try as shown below.
achieved =(grouped.Key.SMCode=="HETAL1" || grouped.Key.SMCode=="BAIJU") ?
grouped.AsEnumerable().Where(x => (x.SalesManCode=="HETAL1"||x.SalesManCode=="BAIJU") &&
x.OrderType == "Sales Invoice" && x.IsFromService==true).Sum(m => m.OrderValue):0

Perl's "not" operator not working as expected with the defined() function

The following snippet is not working as expected:
$k{"foo"}=1;
$k{"bar"}=2;
if(not defined($k{"foo"}) && not defined($k{"bar"})){
print "Not defined\n";
}
else{
print "Defined"
}
Since both $k{"foo"} and $k{"bar"} are defined, the expected output is "Defined". Running the code, however, returns "Not defined".
Now, playing around with the code I realized that placing parentheses around each of the not defined() calls produces the desired result:
if((not defined($k{"foo"})) && (not defined($k{"bar"}))){print "Not Defined"}
I imagine this has something to do with operator precedence but could someone explain what exactly is going on?
Precedence problem.
not defined($k{"foo"}) && not defined($k{"bar"})
means
not ( defined($k{"foo"}) && not defined($k{"bar"}) )
which is equilvalent to
!defined($k{"foo"}) || defined($k{"bar"})
when you actually want
!defined($k{"foo"}) && !defined($k{"bar"})
Solutions:
!defined($k{"foo"}) && !defined($k{"bar"})
not defined($k{"foo"}) and not defined($k{"bar"})
(not defined($k{"foo"})) && (not defined($k{"bar"}))
PS - The language is named "Perl", not "PERL".

How do I use the CoffeeScript existential operator to check some object properties for undefined?

I would like to use the CoffeeScript existential operator to check some object properties for undefined. However, I encountered a little problem.
Code like this:
console.log test if test?
Compiles to:
if (typeof test !== "undefined" && test !== null) console.log(test);
Which is the behavior I would like to see. However, when I try using it against object properties, like this:
console.log test.test if test.test?
I get something like that:
if (test.test != null) console.log(test.test);
Which desn't look like a check against undefined at all. The only way I could have achieved the same (1:1) behavior as using it for objects was by using a larger check:
console.log test.test if typeof test.test != "undefined" and test.test != null
The question is - am I doing something wrong? Or is the compiled code what is enough to check for existence of a property (a null check with type conversion)?
This is a common point of confusion with the existential operator: Sometimes
x?
compiles to
typeof test !== "undefined" && test !== null
and other times it just compiles to
x != null
The two are equivalent, because x != null will be false when x is either null or undefined. So x != null is a more compact way of expressing (x !== undefined && x !== null). The reason the typeof compilation occurs is that the compiler thinks x may not have been defined at all, in which case doing an equality test would trigger ReferenceError: x is not defined.
In your particular case, test.test may have the value undefined, but you can't get a ReferenceError by referring to an undefined property on an existing object, so the compiler opts for the shorter output.
This JavaScript:
a.foo != null
actually does check if the foo property of a is neither undefined nor null. Note that a.foo? is translated to JavaScript that uses != null rather than !== null. The conversions that != does means that both of these are true:
null == null
undefined == null
A plain a? becomes this JavaScript:
typeof a !== "undefined" && a !== null
because there are three conditions to check:
Is there an a in scope anywhere?
Does a have a value of undefined?
Does a have a value of null?
The first condition is important as just saying a != null will trigger a ReferenceError if there is no a in scope but saying typeof a === 'undefined' won't. The typeof check also takes care of the a === undefined condition in 2. Then we can finish it off with a strict a !== null test as that takes care of 3 without the performance penalty of an unnecessary != (note: != and == are slower than !== and === due to the implicit conversions).
A little reading on what != and !== do might be fruitful:
MDN: Comparison Operators
As far as your comment on the deleted answer is concerned, if(a.foo) is perfectly valid syntax if you complete the if statement:
if(a.foo)
do_interesting_things()
# or
do_interesting_things() if(a.foo)
However, if(a.foo) and if(a.foo?) differ in how they handle 0, false, and ''.
Wild guess; have you tried console.log test.test if test?.test??
Just tested it with coffee -p -e 'console.log test.test if test?.test?', which compiles to:
(function() {
if ((typeof test !== "undefined" && test !== null ? test.test : void
0) != null) {
console.log(test.test); }
}).call(this);