Files
Nim/compiler
Corey Leavitt 445d46dd9e fixes #26092; restore enclosing cast block state when a nested cast block exits (#26093)
`unapplyBlockContext` reset `inEnforcedGcSafe` and
`inEnforcedNoSideEffects` to false whenever a `{.cast(gcsafe).}` or
`{.cast(noSideEffect).}` block ended. When such a block is nested inside
another block of the same cast, the inner block's exit switched
enforcement back on for the rest of the enclosing block, so statements
lexically inside the outer cast were rejected.

The fix saves both flags in `PragmaBlockContext` when the block context
is created and restores the saved values on exit. That matches how every
other piece of block state there (`locked`, `exc`, `tags`, `forbids`) is
already handled; these two bools were the only ones reset to a constant
instead of restored.

No change for non-nested blocks: entering from the non-enforced state
saves false, so exit still clears the flag. A statement after the outer
block is still rejected as before.

Test covers nested `cast(gcsafe)` and nested `cast(noSideEffect)`.
`tests/effects` passes unchanged (49/49, same as stock).

(cherry picked from commit f4e8e04cd0)
2026-08-10 08:11:59 +02:00
..
2023-12-15 10:20:57 +01:00
2026-01-09 09:03:51 +01:00
2026-06-12 10:26:34 +02:00
2026-01-09 09:03:51 +01:00
2017-01-07 22:35:09 +01:00
2026-01-09 09:03:51 +01:00
2025-01-15 10:21:20 +01:00
2026-01-09 09:03:51 +01:00
2021-01-12 09:36:51 +01:00
2024-07-09 09:29:45 +02:00
2025-01-14 07:51:55 +01:00
2023-07-02 22:36:05 +02:00
2023-11-06 18:33:28 +01:00
2025-09-22 08:47:23 +02:00
2024-03-16 08:35:18 +08:00
2023-12-25 07:12:54 +01:00

Nim Compiler

  • This directory contains the Nim compiler written in Nim.
  • Note that this code has been translated from a bootstrapping version written in Pascal.
  • So the code is not a poster child of good Nim code.

See Internals of the Nim Compiler for more information.