Deprecate `!a == b`

Quirin Schroll qs.il.paperinik at gmail.com
Tue Aug 13 14:57:08 UTC 2024


On Tuesday, 13 August 2024 at 10:14:29 UTC, Timon Gehr wrote:
> A bug that crops up now and then in D is that someone negates 
> `a == b` by prepending a `!`. The result is `!a == b`. This 
> parses as `(!a) == b` and will often silently do the wrong 
> thing because negation implies cast to `bool`, and `bool` can 
> be compared with integral types and `enum` members.
>
> I think it would be better for this to give a diagnostic and 
> require explicit parentheses, similar to bitwise operators 
> (where the operator precedence is unintuitive in the other 
> direction).

I’m quite sure this requires no DIP. Yes, this is a breaking 
change. The fix is to write `(!a) == b` and it’s unlikely that 
anyone has boatloads of `!a == b` in their code.


More information about the dip.ideas mailing list