diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-11-07 20:53:41 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-11-07 21:17:52 +0100 |
commit | 8a357c270b32d41c2a721dc88197f0a8e35c47e8 (patch) | |
tree | 6b1a47c49c804c064adc9a704f5c784bcfb4d7b3 | |
parent | b1ad5fd7da0d5b93b260ddd62f98f7331cc801fb (diff) | |
download | Nim-8a357c270b32d41c2a721dc88197f0a8e35c47e8.tar.gz |
parser change: 'not' is always a unary operator; fixes #9574
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | compiler/lexer.nim | 2 | ||||
-rw-r--r-- | doc/manual.rst | 3 | ||||
-rw-r--r-- | tests/parser/tprecedence.nim | 5 |
4 files changed, 11 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 10d5510e6..f3ee98fb6 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,8 @@ - The `unchecked` pragma was removed, instead use `system.UncheckedArray`. - The undocumented ``#? strongSpaces`` parsing mode has been removed. +- The `not` operator is now always a unary operator, this means that code like + ``assert not isFalse(3)`` compiles. #### Breaking changes in the standard library diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 877369c2a..76cb88297 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -966,7 +966,7 @@ proc getPrecedence*(tok: TToken, strongSpaces: bool): int = of '?': result = 2 else: considerAsgn(2) of tkDiv, tkMod, tkShl, tkShr: result = 9 - of tkIn, tkNotin, tkIs, tkIsnot, tkNot, tkOf, tkAs: result = 5 + of tkIn, tkNotin, tkIs, tkIsnot, tkOf, tkAs: result = 5 of tkDotDot: result = 6 of tkAnd: result = 4 of tkOr, tkXor, tkPtr, tkRef: result = 3 diff --git a/doc/manual.rst b/doc/manual.rst index e73806147..cb0194ba4 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -514,6 +514,9 @@ are used for other notational purposes. ``*:`` is as a special case treated as the two tokens `*`:tok: and `:`:tok: (to support ``var v*: T``). +The ``not`` keyword is always a unary operator, ``a not b`` is parsed +as ``a(not b)``, not as ``(a) not (b)``. + Other tokens ------------ diff --git a/tests/parser/tprecedence.nim b/tests/parser/tprecedence.nim index d586f14a3..cdf4ad3ee 100644 --- a/tests/parser/tprecedence.nim +++ b/tests/parser/tprecedence.nim @@ -19,3 +19,8 @@ proc foo[S, T](x: S, y: T): T = x & y proc bar[T](x: T): T = x echo "def".foo[:string, string]("abc"), " ", 4.bar[:int] + +# bug #9574 +proc isFalse(a: int): bool = false + +assert not isFalse(3) |