Skip to content

Inconsistent expression evaluation for nested expressions #1260

@jsokolowska

Description

@jsokolowska

Consider following case:

{{ "c" in ["a", "b"] }} // outputs false
{{ !("c" in ["a", "b"]) }} // also outputs false


{% set categories = ["a", "b"] %}
{{  "c" in categories }} // outputs false
{{  !("c" in categories) }} // correctly outputs true

I'd expect expression evaluation to behave the same both for versions - with or without variables used, but it does not.

I've tracked this down to what i believe is a bug in parser

while (s != Symbol.EOF && (depth > 0 || s != Symbol.RPAREN)) {
if (s == LPAREN || s == LBRACK) {
depth++;
} else if (depth > 0 && (s == RPAREN || s == RBRACK)) {
depth--;
} else if (depth == 0) {
if (s == Symbol.COMMA) {
return createAstTuple(params());
}
}
s = lookahead(i++).getSymbol();
}

If there is a coma between ( and ) token parser will interpret it as a tuple declaration and otherwise as nested expression. However this seems incorrect in the above case as I am not trying to declare a tuple, just using a list literal in nested comparison

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions