Files
Nim/compiler
ringabout 5a50254213 fixes #22950; Poor error message on cast effect violation (#25839)
fixes #22950

This pull request improves the tracking and reporting of effect
annotations (such as `raises`, `tags`, and `forbids`) in pragma blocks,
particularly when using the `cast` pragma. It ensures that the source of
these effect annotations is correctly preserved and referenced, which
improves error reporting and effect analysis. Additionally, a new test
was added to check for violations when using `cast` with effect
annotations.

Effect annotation source tracking and propagation:

* Added new fields (`excSource`, `tagsSource`, `forbidsSource`) to the
`PragmaBlockContext` type to store the original source node for each
effect annotation.
* Updated `castBlock` to set these new source fields when processing
`raises`, `tags`, and `forbids` pragmas, ensuring the source node is
preserved for later error reporting.
* Modified `unapplyBlockContext` to use the stored source node (if
available) when calling `addRaiseEffect`, `addTag`, and `addNotTag`,
improving the accuracy of effect tracking and diagnostics.

Pragma handling improvements:

* Changed the call to `castBlock` in the main pragma processing loop to
pass the entire pragma node, enabling access to the original source for
effect annotations.

Testing:

* Added a new test (`tests/effects/tcast_effect_violation.nim`) to
verify that using `cast(raises: ValueError)` inside a procedure with
`.raises: [].` correctly triggers an error message about an unlisted
exception.

(cherry picked from commit cfa769fefc)
2026-05-28 09:22:27 +02:00
..
2023-12-15 10:20:57 +01:00
2026-01-09 09:03:51 +01:00
2026-04-20 09:45:51 +02:00
2026-05-22 08:58:11 +02:00
2026-03-17 10:12:06 +01: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
2026-03-09 10:13:31 +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
2026-01-09 09:03:51 +01: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
2026-04-15 09:23:21 +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.