Skip to content

Commit

Permalink
use arrow precedence in spec (#20166)
Browse files Browse the repository at this point in the history
* test using arrow precedence in spec

refs #8759

* add test for #8759
  • Loading branch information
metagn authored Sep 6, 2022
1 parent 557d79e commit 801eb3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ proc getPrecedence*(tok: Token): int =

# arrow like?
if tok.ident.s.len > 1 and tok.ident.s[^1] == '>' and
tok.ident.s[^2] in {'-', '~', '='}: return 1
tok.ident.s[^2] in {'-', '~', '='}: return 0

template considerAsgn(value: untyped) =
result = if tok.ident.s[^1] == '=': 1 else: value
Expand Down
7 changes: 7 additions & 0 deletions tests/parser/tprecedence.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ let
const
test =
proc(): int = 1

# bug #8759
block:
template `=>`(a, b): untyped = (a, b)
template `+=`(a, b): untyped = a * b

doAssert ("abc" => 3 += 5) == ("abc", 15)

0 comments on commit 801eb3c

Please sign in to comment.