-
-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
A set of conditional operands as for example if (a || b) seems to evaluate all its operands (a and b) upfront.
This means that b will be evaluated even if a was already true.
To Reproduce
Steps to reproduce the behavior:
- Create a leaf file (e.g.
page.leaf) with the following contents:
<!DOCTYPE html>
<html>
<body>
#if(!ctx.children || count(ctx.children) <= 0):
<ul>#for(child in ctx.children):<li>#(child)</li>#endfor</ul>
#else:
<p>No children.</p>
#endif
</body>
</html>
- Render the page with the following context:
struct Context: Encodable { let ctx: [String]? }
func configure(app: Application) {
app.get(use: { $0.view.render("page", Context(ctx: nil)) })
}- Rendering fails with "Unable to convert count parameter to LeafData collection" as thrown by the
Counttag if the parameter is no collection. In this case, a breakpoint inCountprints the following for the first parameter (given thatctx.childrenisnil):
(lldb) po ctx.parameters
▿ 1 element
▿ 0 : void()?
▿ storage : void()?
▿ optional : 2 elements
- .0 : nil
- .1 : LeafKit.LeafData.NaturalType.void
Expected behavior
The page renders fine, showing "No children." with the following rendered HTML:
<!DOCTYPE html>
<html>
<body>
<p>No children.</p>
</body>
</html>Environment
- Vapor Framework version: 4.36.0
- Leaf Framework version: 4.0.1
- LeafKit Framework version: 1.0.0
- Vapor Toolbox version: n/a
- OS version: macOS 11.0.1 as well as Ubuntu 18.04
- Swift version: 5.3.1
Additional context
I tried to dig a bit into LeafKit's source, and am pretty sure that the evaluation of all conditional operands is the problem. However, I could also be missing something, in which case my "attempted diagnosis" might be incorrect and the issue is actually something different.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working