Re: Any way to get a warning if a non-boolean type is used in an if expression?
Re: Any way to get a warning if a non-boolean type is used in an if expression?
- Subject: Re: Any way to get a warning if a non-boolean type is used in an if expression?
- From: Jens Alfke <email@hidden>
- Date: Fri, 18 Oct 2013 11:44:26 -0700
On Oct 18, 2013, at 11:07 AM, Quincey Morris < email@hidden> wrote: Um, one of these things is not like the other.
OK, then basically it was a think-o where he forgot that it needed the .boolValue transformation to become a real boolean. That’s slightly different from what I remembered, but the point is the same.
My point (which perhaps made more sense at 2 am when I came up with it) is that the boolean-ness of 'if (x)' isn't the issue in Rick's case. In C, 'if (x)' is *exactly* equivalent to 'if (x != 0)', which is as boolean-looking a test as Rick could wish, but would be just as wrong as the original code, if 'x' was 'self.active’. But you wouldn’t write “if (x != 0)” for a case where x is (or you believe it to be) a boolean. You’d just write “if (x)”. That’s where the warning would help, by flagging that line if x were not, in fact, a boolean. This would have helped Rick find his mistake at compile time.
—Jens |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden