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

directly parse on/off in pragmas, ignore user override #23097

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,17 @@ 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):
n[1] = newIntTypeNode(1, getSysType(c.graph, n.info, tyBool))
return true
elif ident != nil and ident.id == ord(wOff):
n[1] = newIntTypeNode(0, getSysType(c.graph, n.info, tyBool))
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 +376,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()
14 changes: 14 additions & 0 deletions tests/pragmas/tonoff2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
discard """
action: compile
"""

# issue #22841

import unittest

proc on() =
discard

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