Deprecate `!a == b`
user1234
user1234 at 12.de
Wed Aug 14 14:48:42 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).
Well, just wanna say that this is an easy check to implement in
Dscanner. That does not require any context. Just match the
pattern in the AST and issue a warning.
More information about the dip.ideas
mailing list