Skip to content

Commit 433b725

Browse files
authored
fixes #21975; Pragma block disabling warning has effect beyond block (#24934)
fixes #21975
1 parent 8255338 commit 433b725

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

compiler/semstmts.nim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,9 +2821,24 @@ proc recursiveSetFlag(n: PNode, flag: TNodeFlag) =
28212821
for i in 0..<n.safeLen: recursiveSetFlag(n[i], flag)
28222822
incl(n.flags, flag)
28232823

2824+
proc enterPragmaBlock(c: PContext): POptionEntry =
2825+
result = POptionEntry(options: c.config.options,
2826+
notes: c.config.notes,
2827+
warningAsErrors: c.config.warningAsErrors,
2828+
features: c.features)
2829+
2830+
proc leavePragmaBlock(c: PContext, p: POptionEntry) =
2831+
c.config.options = p.options
2832+
c.config.notes = p.notes
2833+
c.config.warningAsErrors = p.warningAsErrors
2834+
c.features = p.features
2835+
28242836
proc semPragmaBlock(c: PContext, n: PNode; expectedType: PType = nil): PNode =
28252837
checkSonsLen(n, 2, c.config)
28262838
let pragmaList = n[0]
2839+
2840+
let oldOptionEntry = enterPragmaBlock(c)
2841+
28272842
pragma(c, nil, pragmaList, exprPragmas, isStatement = true)
28282843

28292844
var inUncheckedAssignSection = 0
@@ -2848,6 +2863,8 @@ proc semPragmaBlock(c: PContext, n: PNode; expectedType: PType = nil): PNode =
28482863
of wNoRewrite: recursiveSetFlag(result, nfNoRewrite)
28492864
else: discard
28502865

2866+
leavePragmaBlock(c, oldOptionEntry)
2867+
28512868
proc semStaticStmt(c: PContext, n: PNode): PNode =
28522869
#echo "semStaticStmt"
28532870
#writeStackTrace()

tests/pragmas/tpragmablock.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
discard """
2+
matrix: "--warningaserror:BareExcept"
3+
"""
4+
5+
{.warning[BareExcept]:on.}:
6+
discard
7+
8+
try:
9+
echo "Y"
10+
except: # warning disabled here
11+
discard

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy