Skip to content

derive: make EvaluatedResult know its unknown result#538

Merged
GuillaumeGomez merged 1 commit intoaskama-rs:masterfrom
Kijewski:pr-always-false
Jul 23, 2025
Merged

derive: make EvaluatedResult know its unknown result#538
GuillaumeGomez merged 1 commit intoaskama-rs:masterfrom
Kijewski:pr-always-false

Conversation

@Kijewski
Copy link
Copy Markdown
Member

This PR adds a WithSpan<Expr> member to EvaluatedResult::Unknown, so Generator::evaluate_condition() does not have to return a tuple.

Resolves #535.

(Can a discussion be resolved? I guess I'll stick with issues again in the future.)

// condition.
compare(
"{% if y == 3 || (true || x == 12) %}{{x}}{% endif %}",
r"if askama::helpers::as_bool(&(self.y == 3)) || (true) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expr::BinOp(v) if v.op == "||" => .. and Expr::BinOp(v) if v.op == "&&" => .. don't build a binary op anymore if the outcome of one leg is known. Except for expr && false, which keeps expr for its side effect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that's wrong. Will fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expr::Group(_) now directly returns true or false if the result is known, instead of (true) or (false). That's why there is still a change in this line, but I fixed my previous mistake. :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! That's an improvement. :)

This PR adds a `WithSpan<Expr>` member to `EvaluatedResult::Unknown`,
so `Generator::evaluate_condition()` does not have to return a tuple.
@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

This is much better, thanks!

@GuillaumeGomez GuillaumeGomez merged commit 8dcc794 into askama-rs:master Jul 23, 2025
42 checks passed
@Kijewski Kijewski deleted the pr-always-false branch July 23, 2025 13:16
@Kijewski Kijewski mentioned this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants