Deprecate `!a == b`
Lance Bachmeier
no at spam.net
Tue Aug 13 16:41:15 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).
This should be done. The current behavior isn't likely something
that's used very often (testing equality of two bools). Breaking
code isn't a problem because !a == b would fail to compile, and
it's trivial to fix. Other changes to the language have been more
annoying while providing less benefit.
More information about the dip.ideas
mailing list