api/types/filters: GetBoolOrDefault: remove unreachableCode#48745
api/types/filters: GetBoolOrDefault: remove unreachableCode#48745thaJeztah merged 1 commit intomoby:masterfrom
Conversation
| invalid := !isFalse && !isTrue | ||
|
|
||
| if conflicting || invalid { | ||
| if isFalse == isTrue { |
There was a problem hiding this comment.
This will be true if the there are conflicting values specified (both truthy and falsy), in which case it will be treated as truthy value.
(like filter=true,filter=false)
There was a problem hiding this comment.
Right, but that was the case before as well, correct?
conflicting := isFalse && isTrue
invalid := !isFalse && !isTrue
if conflicting || invalid {
The above; if both are false or both are true we return default value (with an error), so that's the same as if isFalse == isTrue`
There was a problem hiding this comment.
Oh, right.
I guess that's why I went with a more explicit code, so it's easier to wrap your head around truthness and falseness of isFalse and isTrue variables 😅
There was a problem hiding this comment.
I can add a comment "a boolean cannot be both true and false" ?
There was a problem hiding this comment.
Not sure that's helpful 🙈
Maybe something like:
| if isFalse == isTrue { | |
| // Either no or conflicting truthy/falsy value were provided | |
| if isFalse == isTrue { |
We already check if - the key is set (otherwise default) - a value is set (otherwise default and error) This check can be simplified to check if they're equal (boolean cannot be both true and false), or both false (boolean must be either true or false), although the latter could be considered for a tri-state boolean (but we already do this through the "not set" case). We may need some additional checks, for example, currently it ignores invalid values if the filter contains at least one valid one (e.g. ["true", "bananas"]). Signed-off-by: Sebastiaan van Stijn <[email protected]>
40efc3c to
7d70892
Compare
We already check if
This check can be simplified to check if they're equal (boolean cannot be both true and false), or both false (boolean must be either true or false), although the latter could be considered for a tri-state boolean (but we already do this through the "not set" case).
We may need some additional checks, for example, currently it ignores invalid values if the filter contains at least one valid one (e.g. ["true", "bananas"]).
- A picture of a cute animal (not mandatory but encouraged)