Skip to content

Guard expressions regression in 2.6.0 #2798

Closed

Description

@nborko
.test when ((8+4) < 13) { 1: 2; }

will error with:

SyntaxError: expected ')' got '<'

Activity

  1. seven-phases-max commented on Feb 2, 2016

    @seven-phases-max
    Member

    It's most likely because of #2763 (it seems that this kind of expressions is not covered by tests unfortunately).

  2. changed the title [-]Handing parentheses in expressions appears broken in 2.6.0[/-] [+]Guard expressions regression in 2.6.0[/+] on Feb 2, 2016
  3. seven-phases-max commented on Feb 2, 2016

    @seven-phases-max
    Member

    A minimal examples to reproduce:

    x when ((3) < 4) {
        y: z;    
    }
    x when ((3) + 4) {
        y: z;    
    }
    etc.
  4. SomMeri commented on Feb 7, 2016

    @SomMeri
    Member

    I will have a look at this, next week at latest. Adding some new tests might be a good idea too.

  5. seven-phases-max commented on Feb 7, 2016

    @seven-phases-max
    Member

    I'm trying to fix this too (not sure if I'll be capable to do this earlier though - from what I can see so far, we'll definitely need to consider to switch asap from when (true) and (true) or (true) thing to more conventional (true and true or true), because the parsing of irregular and directly opposite parens patterns for logical-and-or-not and logical-anything-else expressions incredibly clutters the code (not counting not-so-friendly-and-easy to explain/understand guards usage in a long run)).

  6. SomMeri commented on Feb 7, 2016

    @SomMeri
    Member

    You mean not require parenthesis around true and false? It would make sense to me.

  7. seven-phases-max commented on Feb 7, 2016

    @seven-phases-max
    Member

    You mean not require parenthesis around true and false?

    Yes, but not only. It's actually more about requiring outer parens after when and for anything else parens to be optional. But in either case this would mean a breaking change.
    I.e.:

    • with "required outer parens", currently valid when (true) and (true) or (true) becomes illegal
    • with "optional outer parens", too ambiguous stuff like when true, true > false comes in (sincetrue > false is also a selector).
  8. SomMeri commented on Feb 7, 2016

    @SomMeri
    Member

    I recall that when is allowed only in rulesets with one selector, so that concrete example of optional outer parens should not be ambigous. It was discussed in some issue a while ago.

  9. seven-phases-max commented on Feb 7, 2016

    @seven-phases-max
    Member

    I recall that when is allowed only in rulesets with one selector,

    And it's the parser that has to test for , ( pattern and throw a error if it's just , .... So we either have to throw away , as an or operator, or require parens after , (and thus after when in general) at least to distinguish between condition, selector and condition, condition.
    A breaking change in any case.

  10. SomMeri commented on Feb 8, 2016

    @SomMeri
    Member

    @seven-phases-max Cant we just assume that what follows , is another condition, try to parse out that condition and fail only if it is not there? We do not have to use the , ( optimization.

  11. SomMeri commented on Feb 8, 2016

    @SomMeri
    Member

    Interestingly, these works:

    • .test when (8+4 < 13) {}
    • .test when (8+(5-1) < 13) {}
    • .test when (8 < (13+1))

    It seems like it specifically does not allow parenthesis around left side.

  12. seven-phases-max commented on Feb 8, 2016

    @seven-phases-max
    Member

    Cant we just assume that what follows , is another condition, try to parse out that condition and fail only if it is not there?

    We can. But then someone writes something like:

    html when true, 
    body {
       font-size: 16px
    }

    and the compiler interprets it as

    html when true, false {
       font-size: 16px;
    }

    thus silently throwing body away (as it's parsed as valid (keyword) condition evaluating to false).
    We still can require () after the comma but it will get us back to:

    when true or false {}
    when true, (false) {}
    // why they are different?
    

    or

    when (true or false) {}
    when (true), (false) {}
    // why they are different?
    
  13. seven-phases-max commented on Feb 8, 2016

    @seven-phases-max
    Member

    Interestingly, these works: .test when (8+4 < 13) {}

    Yes, I suppose this is because when we have the first inner parens in when ((x) < 3) the parser enters condition() -> conditionAnd() and stops here thus still returning properly parsed (x) value ( stored as (x = true) condition), but next comes only < 3 which isn't already parseable (since neither of comparision operands can be a condition(), thus the parser can't even try the other way around). <- well, roughly...

    And the reverted expression works simply because the parser instantly goes down to this.addition() and "incomplete and/or values" don't interfere there.

  14. 3 remaining items

  15. matthew-dean commented on Feb 11, 2016

    @matthew-dean
    Member

    That is:

    when true or false {}   // should fail
    when true, (false) {}    // should fail
    when (true or false) {}   // should pass
    when (true), (false) {}   // should pass
    
  16. seven-phases-max commented on Feb 11, 2016

    @seven-phases-max
    Member

    being illegal outside of parentheses, which it doesn't have to be.

    It depends on what we're about. If it's about the current behaviour then there's no , issue, nothing to discuss.
    If we're about #2807, then there're two variants as in #2798 (comment). The first variant bans the comma at all, and the second variant is about to ban it too (otherwise the mentioned ambiguity jumps in).

  17. matthew-dean commented on Feb 11, 2016

    @matthew-dean
    Member

    The first variant bans the comma at all, and the second variant is about to ban it too (otherwise the mentioned ambiguity jumps in).

    I don't see how. o_O Any comma after a when and before { is part of the when statement.

  18. seven-phases-max commented on Feb 11, 2016

    @seven-phases-max
    Member

    Any comma after a when and before { is part of the when statement.

    It's not even true for the current behaviour. And especially it doesn't have to be for the planned one.

  19. matthew-dean commented on Feb 11, 2016

    @matthew-dean
    Member

    @seven-phases-max

    It's not even true for the current behaviour.

    Then that's a bug. when statements can have commas. They shouldn't be treated differently than mixin guards.

  20. SomMeri commented on Feb 11, 2016

    @SomMeri
    Member

    @matthew-dean @seven-phases-max I think that comma after when inside ruleset is a bug, but different one then this one. It might even be harder to fix.

  21. seven-phases-max commented on Feb 11, 2016

    @seven-phases-max
    Member

    @matthew-dean @SomMeri
    I don't see any bug in the example of #2798 (comment).
    It's actually just a more user-friendly error message for the ambiguous syntax - if you remove that special test for , (, the error becomes just unrecongnised input, expected condition (is that what would you expect?).

  22. matthew-dean commented on Feb 11, 2016

    @matthew-dean
    Member

    @seven-phases-max By a bug, I mean that it's weird (unexpected) that a mixin can have a comma-guard and a selector can't. That said, per: #2807 (comment), let's get rid of the comma soon.

  23. SomMeri commented on Feb 11, 2016

    @SomMeri
    Member

    I considered it a bug for the same reason as @matthew-dean - because it is different then in mixin. I agree with deprecating comma for 3.0.

  24. seven-phases-max commented on Feb 11, 2016

    @seven-phases-max
    Member

    it's weird (unexpected) that a mixin can have a comma-guard and a selector can't.

    I guess you both are missing that x ruleset there is actually valid and compiles fine, it's only the invalid y that throws the error. So still no real bug there (the example is only used to illustrate the ambiguity if we would allow the "all-parens-optional" syntax and don't ban comma).

  25. matthew-dean commented on Feb 11, 2016

    @matthew-dean
    Member

    I guess you both are missing that x ruleset there is actually valid and compiles fine, it's only the invalid y that throws the error. So still no real bug there

    The bug would be that y should not be invalid if y is a valid when condition.

    If there's consensus, though, we could mark that bug as "wontfix" until the comma is deprecated / removed. The docs don't yet mention the "or" keyword though.

  26. SomMeri commented on Feb 11, 2016

    @SomMeri
    Member

    @matthew-dean I created new issue for that in docs #396.

    Btw, it is great that less.js is getting more active lately 👍 .

  27. added a commit that references this issue on Feb 17, 2016
    c12a7df
  28. added a commit that references this issue on Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions