You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Commenting in the @is-baz variable on line 6 (and line 10 to use it in an expression) causes the error variable @is-baz is undefined. As you can see, the expression @is-baz contains is the same is the (working) @is-qar expression, but inlines the @foo-is-one and @bar-is-a checks.
Expected behavior:
There shouldn't be any undefined variable, because the variable is defined — I should be allowed to inline boolean expressions / logical comparisons like so.
This is a parser design limitation rather than a bug. When you write boolean((@foo = 1) = (@bar = a)), the parser creates Condition objects for each comparison (@foo = 1 and @bar = a), but these Condition objects cannot be used as operands in another comparison.
Your working example succeeds because boolean()returns actual boolean keyword values (true/false) when evaluated. When you store those in @foo-is-one and @bar-is-a, they become regular values that can be compared.
The parser only allows multiple conditions to be combined through logical and/or operators, not through nested comparisons. So you'd need to stick with the intermediate variable approach you've already found.
The type of expression I'm trying to make work is comparing the result of two boolean comparisons. I want to get the output of a = b, where a itself is a comparison expression and b itself is also a comparison expression.
It shows that --baz is true. However, if I take away the boolean function wrapper around the expressions @foo = 1 and @bar = a:
@foo: 1;
@bar: a;
@baz: boolean((@foo=1) = (@bar=a)); // should still be true?:root {
--baz: @baz; // compile error
}
I get this error: variable @baz is undefined.
For what it is worth, the JavaScript equivalent of this expression can be seen in the following:
Where baz is showing that the two comparisons have the same result.
In redescribing the problem, I think there are a couple takeaways:
Should Less require the boolean function within an existing boolean expression (aka inside another boolean() function call)? This is shown by the first Less example working and the second not.
If this is the intended behavior - just use the boolean function when doing these kind of weird comparisons - perhaps this is more of a vague error issue where the error message is incorrect: the error should probably tell me that my expression is invalid, rather then the variable being undefined.
That comparison is slightly different - in that, @baz will show false if the two comparisons are both false. My earlier logic was checking if the comparisons returned the same boolean, not if they were both true.
@foo: 1;
@bar: a;
@baz: boolean((@foo=100) and (@bar= abcdef));
:root {
--baz: @baz; // false but true expected
}
If you replace the and with an = sign, Less errors again with a nonsensical message.
Activity
dosubot commentedon Mar 3, 2026
This is a parser design limitation rather than a bug. When you write
boolean((@foo = 1) = (@bar = a)), the parser createsConditionobjects for each comparison (@foo = 1and@bar = a), but theseConditionobjects cannot be used as operands in another comparison.Your working example succeeds because
boolean()returns actual boolean keyword values (true/false) when evaluated. When you store those in@foo-is-oneand@bar-is-a, they become regular values that can be compared.The parser only allows multiple conditions to be combined through logical
and/oroperators, not through nested comparisons. So you'd need to stick with the intermediate variable approach you've already found.To reply, just mention @dosu.
Docs are dead. Just use Dosu.
matthew-dean commentedon Mar 10, 2026
It's really unclear from your example what the correct input is and what your expected output is. Can you simplify?
uncenter commentedon Mar 10, 2026
Yeah of course.
The type of expression I'm trying to make work is comparing the result of two boolean comparisons. I want to get the output of
a = b, whereaitself is a comparison expression andbitself is also a comparison expression.The following Less code works:
It shows that
--bazistrue. However, if I take away thebooleanfunction wrapper around the expressions@foo = 1and@bar = a:I get this error:
variable @baz is undefined.For what it is worth, the JavaScript equivalent of this expression can be seen in the following:
Where
bazis showing that the two comparisons have the same result.In redescribing the problem, I think there are a couple takeaways:
booleanfunction within an existing boolean expression (aka inside anotherboolean()function call)? This is shown by the first Less example working and the second not.matthew-dean commentedon Jun 16, 2026
@uncenter The error message is bad but Less supports a media-query-like or container-query-like syntax, so the correct way to write it is:
uncenter commentedon Jun 17, 2026
That comparison is slightly different - in that,
@bazwill showfalseif the two comparisons are both false. My earlier logic was checking if the comparisons returned the same boolean, not if they were both true.If you replace the
andwith an=sign, Less errors again with a nonsensical message.This is still true even though
foois not100andbaris notabcdef, because both are false and the comparison results are the same.