From 00ac961ab18c6c8cba9fd2bdad8390816dec1ec8 Mon Sep 17 00:00:00 2001 From: metagn Date: Wed, 18 Sep 2024 23:45:19 +0300 Subject: require `not nil` to be on the same line after a type (#24134) fixes #23565 --- compiler/parser.nim | 2 +- tests/parser/tbinarynotindented.nim | 3 +++ tests/parser/tbinarynotsameline.nim | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/parser/tbinarynotindented.nim create mode 100644 tests/parser/tbinarynotsameline.nim diff --git a/compiler/parser.nim b/compiler/parser.nim index eb7b8c289..747505097 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1401,7 +1401,7 @@ proc primary(p: var Parser, mode: PrimaryMode): PNode = result = primarySuffix(p, result, baseInd, mode) proc binaryNot(p: var Parser; a: PNode): PNode = - if p.tok.tokType == tkNot: + if p.tok.tokType == tkNot and p.tok.indent < 0: let notOpr = newIdentNodeP(p.tok.ident, p) getTok(p) optInd(p, notOpr) diff --git a/tests/parser/tbinarynotindented.nim b/tests/parser/tbinarynotindented.nim new file mode 100644 index 000000000..8d124aade --- /dev/null +++ b/tests/parser/tbinarynotindented.nim @@ -0,0 +1,3 @@ +type Foo = ref int + not nil #[tt.Error + ^ invalid indentation]# diff --git a/tests/parser/tbinarynotsameline.nim b/tests/parser/tbinarynotsameline.nim new file mode 100644 index 000000000..ca417e023 --- /dev/null +++ b/tests/parser/tbinarynotsameline.nim @@ -0,0 +1,10 @@ +# issue #23565 + +func foo: bool = + true + +const bar = block: + type T = int + not foo() + +doAssert not bar -- cgit 1.4.1-2-gfad0