diff options
author | metagn <metagngn@gmail.com> | 2024-06-05 21:53:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-05 20:53:05 +0200 |
commit | 42e8472ca6eab740c0879428bd119ec94e70fe74 (patch) | |
tree | 607c7fac70fe5138e9220fcc6ba20972bbfac6b4 /lib/std/syncio.nim | |
parent | 77c04092e01c7f42b5697ec0ec9e71352f628023 (diff) | |
download | Nim-42e8472ca6eab740c0879428bd119ec94e70fe74.tar.gz |
fix noreturn/implicit discard check logic (#23681)
fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677 The false positive in #23677 was caused by behavior in `implicitlyDiscardable` where only the last node of `if`/`case`/`try` etc expressions were considered, as in the final node of the final branch (in this case `else`). To fix this we use the same iteration in `implicitlyDiscardable` that we use in `endsInNoReturn`, with the difference that for an `if`/`case`/`try` statement to be implicitly discardable, all of its branches must be implicitly discardable. `noreturn` calls are also considered implicitly discardable for this reason, otherwise stuff like `if true: discardableCall() else: error()` doesn't compile. However `endsInNoReturn` also had bugs, one where `finally` was considered in noreturn checking when it shouldn't, another where only `nkIfStmt` was checked and not `nkIfExpr`, and the node given for the error message was bad. So `endsInNoReturn` now skips over `skipForDiscardable` which no longer contains `nkIfStmt`/`nkCaseStmt`/`nkTryStmt`, stores the first encountered returning node in a var parameter for the error message, and handles `finally` and `nkIfExpr`. Fixing #23677 already broke a line in `syncio` so some package code might be affected.
Diffstat (limited to 'lib/std/syncio.nim')
-rw-r--r-- | lib/std/syncio.nim | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index 2b39375ea..c34a025af 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -874,7 +874,7 @@ proc writeFile*(filename: string, content: openArray[byte]) {.since: (1, 1).} = var f: File = nil if open(f, filename, fmWrite): try: - f.writeBuffer(unsafeAddr content[0], content.len) + discard f.writeBuffer(unsafeAddr content[0], content.len) finally: close(f) else: |