Skip to content
Tcl Source Code View Ticket
Login

View Ticket

"!" operator can't handle string booleans

Closed / Fixed219153ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 05:02:22
OriginalBugID: 1194 RFE
Version: 8.1b1
SubmitDate: '1999-02-11'
LastModified: '1999-12-03'
Severity: LOW
Status: Assigned
Submitter: pat
ChangedBy: hobbs
RelatedBugIDs: 616
OS: Linux
OSVersion: 2.0.35
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
Steve McAndrewSmith

ReproducibleScript:
# These all work fine ...
set b 1
if { $b } { puts "ooga" }

set b 0
if { ! $b } { puts "ooga" }

set b yes
if { $b } { puts "ooga" }

set b no
if { $b } { puts "no ooga" } else { puts "ooga" }

if { ($b && $b) || $b } { puts "ooga ooga ooga" }

# This produces an error.:  can't use non-numeric string as operand of "!"
if { ! $b } { puts "GAKK!" }

ObservedBehavior:
When using string boolean values (e.g. "true", "false", "yes", "no") in if expressions, the negation operator ("!") does not recognize the strings as boolean values.  Only "0" and "1" are correctly accepted.  It gives the following error:

  can't use non-numeric string as operand of "!" 

However, both "&&" and "||" (and probably others) accept these boolean strings correctly.

DesiredBehavior:
"!true",  "!false", "!yes", and "!no" should all evaluate correctly.



This is not the defined behavior.  03/23/1999 18:13 - surles -
dkfplain2000-11-24 22:14:36
Added test to detect this.
dkfplain2000-11-24 22:28:03
Now handles the variable case properly.  Only a problem now if expressions are not quoted properly with braces.
dkf Ticket [219153ffff]: 1 change [History diff]2001-04-09 16:56:17
dkfplain2001-04-09 16:56:18
Logged In: YES 
user_id=79902

Now handles the non-numeric boolean literal case properly.
This bug is now 100% resolved.
Log in (anonymous is fine) to add a comment.