Open DougGregor opened 3 months ago
Synced to Apple’s issue tracker as rdar://128016621
Could this code action extend to cover bitwise operators as well?
Yes, that would make sense.
@ahoppen as you mentioned in #1539, being overly restrictive is more of a problem than being too permissive. However for DeMorgan's law, the situation is a bit different. We may identify multiple candidate expressions as we walk up the syntax tree, e.g. !(a != b || !(c && d))
, which I believe isn't a terribly uncommon form of expression.
I can think of two possible ways to deal with the ambiguity,
It’s probably one of these situations where we need some reference implementation and then use it to decide what feels best. But I think starting with the outermost expression makes sense as a start.
Shall we support generalised DeMorgan's in addition to dual DeMorgan's?
e.g. !a && !b && !c
-> !(a || b || c)
I would start with one direction. The dual would be a nice follow-up after that.
Description
Sometimes in code we end up with something like:
and it would be cleaner to apply DeMorgan's law to make this:
We should have a code action to do this correctly, which requires dealing with inverting conditions and dealing with operator precedence. The
SwiftOperators
module of swift-syntax can help here.