On Sep 19, 2013, at 00:34, [email protected] wrote:

>>> +if {$subport != "aqbanking5-svn"} {
>> == and != are for numeric comparisons. For string comparisons, you should 
>> use eq or ne. (Yes, this issue is pervasive and needs to be fixed in a lot 
>> of ports.)
> 
> Thanks for spotting this one!
> Changed in r111344.
> 
> Crazy that even "port lint --nitpick" didn't find this!!!
> 
> I suggest to improve the lint command to avoid stuff like this in the future.
> 
> (Still, it seems to have worked with "!=" as well.)


Earlier this year someone pointed out on the list that == and != are actually 
designed for numeric comparisons. If the values can't be interpreted as 
numbers, Tcl will do a string comparison instead. However, if you already know 
you want to compare strings, you should use eq and ne to avoid surprises.

It would be nice if lint would catch this type of error, but it's perhaps not 
very simple to do that in every case. For example:

if {${a} == ${b}} { … }

Is this line correct, or should this == really be eq? It's not possible to know 
without knowing whether ${a} and ${b} are numbers or strings, and lint doesn't 
know that.

Lint could perhaps catch a few common occurrences of this error, such as:

if {${a} == "…"} # clearly wrong because the RHS is a string literal

if {{…} != ${a}} # clearly wrong because the LHS is a string literal

if {${name} != ${subport}} # special-case the variables "name" and "subport" 
because we know they're strings

_______________________________________________
macports-dev mailing list
[email protected]
https://lists.macosforge.org/mailman/listinfo/macports-dev

Reply via email to