nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Pragma block disabling warning has effect beyond block #21975

Open tersec opened 1 year ago

tersec commented 1 year ago

Description

{.warning[BareExcept]:off.}:
  try:
    echo "X"
  except:  # warning disabled here
    discard

try:
  echo "Y"
except:  # warning disabled here
  discard

Both https://nim-lang.org/docs/manual.html#effect-system-side-effects and https://nim-lang.org/docs/manual.html#effect-system-gc-safety-effect refer to this notion of a "pragma block", and provide similar examples, but in this case, the pragma has effect beyond the block, and does not appear to be meaningfully scoped.

Nim Version

Nim Compiler Version 1.6.12 [Linux: amd64]
Compiled at 2023-05-21
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 1aa9273640c0c51486cf3a7b67282fe58f360e91
active boot switches: -d:release
Nim Compiler Version 1.9.3 [Linux: amd64]
Compiled at 2023-05-31
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b880cdff49576c0eb83a043cbae595d3587c95b4
active boot switches: -d:release

Current Output

No compile warnings or errors

Expected Output

repro.nim(9, 1) Warning: The bare except clause is deprecated; use `except CatchableError:` instead [BareExcept]

on second, but not first, try/except

Possible Solution

No response

Additional Information

No response

metagn commented 1 year ago

This is just unimplemented, it understands warning[BareExcept]:off then treats the rest like a normal expression. Pragma block behavior here