Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parser] a => counter+=1 parsed as (a => counter) += 1, violating the spec, and causing issues with => #8759

Closed
timotheecour opened this issue Aug 24, 2018 · 1 comment · Fixed by #20166
Labels

Comments

@timotheecour
Copy link
Member

timotheecour commented Aug 24, 2018

/cc @Araq

import macros

dumpTree:
  # violates spec: arrow like operators have lowest precedence
  a1 => counter += 2
  # ditto
  a2 => counter *= 2
  # violates spec: `^` should have higher precedence than += (regardless of `^` being right-associative)
  a3 ^= counter += 2
StmtList
  Infix
    Ident "+="
    Infix
      Ident "=>"
      Ident "a1"
      Ident "counter"
    IntLit 2
  Infix
    Ident "*="
    Infix
      Ident "=>"
      Ident "a2"
      Ident "counter"
    IntLit 2
  Infix
    Ident "^="
    Ident "a3"
    Infix
      Ident "+="
      Ident "counter"
      IntLit 2

NOTE

this affects sugar.nim =>, zero-functional, and lambda PR #8679

spec:

https://github.com/nim-lang/Nim/blob/devel/doc/manual.rst#L573
/Users/timothee/git_clone/nim/Nim/doc/manual.rst

@metagn
Copy link
Collaborator

metagn commented Jul 12, 2022

1 here has to be 0. I would almost hope it's not a typo because it's been there since the initial implementation of arrow operators (2014).

tok.ident.s[^2] in {'-', '~', '='}: return 1

metagn added a commit to metagn/Nim that referenced this issue Aug 5, 2022
metagn added a commit to metagn/Nim that referenced this issue Aug 12, 2022
metagn added a commit to metagn/Nim that referenced this issue Aug 12, 2022
metagn added a commit to metagn/Nim that referenced this issue Aug 12, 2022
Araq pushed a commit that referenced this issue Sep 6, 2022
* test using arrow precedence in spec

refs #8759

* add test for #8759
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* test using arrow precedence in spec

refs nim-lang#8759

* add test for nim-lang#8759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants