Commit cfa769f
authored
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.
1 parent 8771451 commit cfa769f
2 files changed
Lines changed: 18 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1208 | 1208 | | |
1209 | 1209 | | |
1210 | 1210 | | |
| 1211 | + | |
1211 | 1212 | | |
1212 | 1213 | | |
1213 | 1214 | | |
| |||
1230 | 1231 | | |
1231 | 1232 | | |
1232 | 1233 | | |
1233 | | - | |
| 1234 | + | |
1234 | 1235 | | |
1235 | 1236 | | |
1236 | 1237 | | |
1237 | | - | |
| 1238 | + | |
1238 | 1239 | | |
1239 | 1240 | | |
1240 | 1241 | | |
1241 | | - | |
| 1242 | + | |
1242 | 1243 | | |
1243 | | - | |
| 1244 | + | |
| 1245 | + | |
1244 | 1246 | | |
1245 | 1247 | | |
1246 | 1248 | | |
| |||
1253 | 1255 | | |
1254 | 1256 | | |
1255 | 1257 | | |
| 1258 | + | |
1256 | 1259 | | |
1257 | 1260 | | |
1258 | 1261 | | |
1259 | 1262 | | |
1260 | 1263 | | |
1261 | 1264 | | |
1262 | 1265 | | |
| 1266 | + | |
1263 | 1267 | | |
1264 | 1268 | | |
1265 | 1269 | | |
1266 | 1270 | | |
1267 | 1271 | | |
1268 | 1272 | | |
1269 | 1273 | | |
| 1274 | + | |
1270 | 1275 | | |
1271 | 1276 | | |
1272 | 1277 | | |
| |||
1520 | 1525 | | |
1521 | 1526 | | |
1522 | 1527 | | |
1523 | | - | |
| 1528 | + | |
1524 | 1529 | | |
1525 | 1530 | | |
1526 | 1531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments