-
Notifications
You must be signed in to change notification settings - Fork 39
derive: in complex conditions, wrap terms in as_bool()
#203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Before this PR, the whole condition in `{% if cond %}` got wrapped in
`as_bool(&cond)`. With is PR, the individual terms in a binary operation
`&&` or `||`, or unary operation `!` get wrapped in `as_bool()`.
|
In travel currently. Will take a look when I'm back next week. :) |
|
No problem at all! Enjoy your trip, I wish you good weather! :) 🌞 |
| compare( | ||
| "{% if let Some(query) = s && !query.is_empty() %}{{query}}{% endif %}", | ||
| r"if let Some(query,) = &self.s && !query.is_empty() { | ||
| r"if let Some(query,) = &self.s && !rinja::helpers::as_bool(&(query.is_empty())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In such cases, I'm not sure it's an improvement since the ! operator tells us that it's already a boolean.
| "{% if y == 3 || (x == 12 || true) %}{{x}}{% endif %}", | ||
| r"if *(&(self.y == 3 || (self.x == 12 || true)) as &rinja::helpers::core::primitive::bool) { | ||
| r" | ||
| if rinja::helpers::as_bool(&(self.y == 3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in this case, it's a comparison so we already know for sure it's a boolean.
|
It's work travel so the weather doesn't really matter. 😆 |
|
Also, as seen in redlib-org/redlib#290 (comment), the current implementation can be confusing. In the condition |
|
Oh I see, makes sense. Thanks for the extra explanation. :) |
Before this PR, the whole condition in
{% if cond %}got wrapped inas_bool(&cond). With is PR, the individual terms in a binary operation&&or||, or unary operation!get wrapped inas_bool().Resolves #201.