Skip to content

Commit

Permalink
directly parse on/off in pragmas, ignore user override
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 18, 2023
1 parent 080a072 commit 53a88b8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
16 changes: 10 additions & 6 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,15 @@ proc wordToCallConv(sw: TSpecialWord): TCallingConvention =
proc isTurnedOn(c: PContext, n: PNode): bool =
result = false
if n.kind in nkPragmaCallKinds and n.len == 2:
let x = c.semConstBoolExpr(c, n[1])
n[1] = x
if x.kind == nkIntLit: return x.intVal != 0
let ident = getPIdent(n[1])
if ident != nil and ident.id == ord(wOn):
return true
elif ident != nil and ident.id == ord(wOff):
return false
else:
let x = c.semConstBoolExpr(c, n[1])
n[1] = x
if x.kind == nkIntLit: return x.intVal != 0
localError(c.config, n.info, "'on' or 'off' expected")

proc onOff(c: PContext, n: PNode, op: TOptions, resOptions: var TOptions) =
Expand Down Expand Up @@ -368,9 +374,7 @@ proc processNote(c: PContext, n: PNode) =
let x = findStr(enumVals.a, enumVals.b, n[0][1].ident.s, errUnknown)
if x != errUnknown:
nk = TNoteKind(x)
let x = c.semConstBoolExpr(c, n[1])
n[1] = x
if x.kind == nkIntLit and x.intVal != 0: incl(notes, nk)
if isTurnedOn(c, n): incl(notes, nk)
else: excl(notes, nk)
else:
invalidPragma(c, n)
Expand Down
1 change: 1 addition & 0 deletions tests/pragmas/monoff1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proc on*() = discard
8 changes: 8 additions & 0 deletions tests/pragmas/tonoff1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# issue #23002

import monoff1

proc test() =
{.warning[ProveInit]: on.}

test()
10 changes: 10 additions & 0 deletions tests/pragmas/tonoff2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# issue #22841

import unittest

proc on() =
discard

suite "some suite":
test "some test":
discard

0 comments on commit 53a88b8

Please sign in to comment.