Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finally: with multiple expressions in a single line doesn't work as expected #412

Closed
gradha opened this issue May 1, 2013 · 2 comments
Closed
Labels

Comments

@gradha
Copy link
Contributor

gradha commented May 1, 2013

The following code compiles:

import db_sqlite, os

proc cleaners(name: string) =
  var conn = db_sqlite.open(name, "user", "pass", "db")
  conn.exec(sql"""CREATE TABLE IF NOT EXISTS tests (
    id INTEGER PRIMARY KEY,
    data TEXT NOT NULL)""")

  finally: conn.close(); removeFile(name)
  echo "Going to insert stuff..."
  conn.exec(sql"INSERT INTO tests (data) VALUES (?)", "test string")
  echo "Inserted!"


when isMainModule:
  cleaners("test.db")

However, it fails to run with the following output:

Going to insert stuff...
Traceback (most recent call last)
dbfail.nim(16)           dbfail
dbfail.nim(9)            cleaners
db_sqlite.nim(181)       Close
db_sqlite.nim(41)        dbError
Error: unhandled exception: unable to close due to unfinalised statements [EDb]
Error: execution of an external program failed

The problem is with the finally having more than one statement in a single line. The example works as expected if I rewrite that part as:

  finally:
    conn.close()
    removeFile(name)

The ; is clearly evil.

@gradha
Copy link
Contributor Author

gradha commented May 1, 2013

Hmm... so the problem is the ; in a single line makes the removeFile execute out of the finally context, and then the next sqlite command fails likely due to being unable to lock the removed database file. Not sure if this counts as a bug then, will the new parser take this in mind or will you need parenthesis around both statements for it to work as expected? If not, maybe the parser should warn about this behaviour of finally: on a single line or simply not compile it?

@Araq Araq closed this as completed Jun 3, 2013
@dom96
Copy link
Contributor

dom96 commented Jun 3, 2013

Fixed by 255b4d9

Clyybber pushed a commit to Clyybber/Nim that referenced this issue Nov 7, 2022
…nim-lang#401 nim-lang#402 nim-lang#403 nim-lang#405 nim-lang#406 nim-lang#407 nim-lang#409 nim-lang#410 nim-lang#411 nim-lang#412 nim-lang#413

392: internal: remove sons from leaf nodes empty/none r=disruptek a=saem

## Summary
- pulls nkEmpty and nkNone into a branch without sons
- ensures more correctness by design

## Details
- various small fixes to get bootstrap working
- no tests failed, so that's a good{?} sign



395: stdlib: remove deprecated modules r=disruptek a=saem

deprecated stdlib module removal:
- removed events, LockFreeHash, parseopt2, and securehash
- associated clean-up in testament
- lib/deprecate/pure now only contains ospaths, an include for os
- remove events related tests

396: lang: remove deprecated c/C octal prefix r=disruptek a=saem

## Summary
- can no longer use 0c1
- this has long since been deprecated and not referenced in the manual


397: macros: remove deprecated TNimSym/TypeKinds r=disruptek a=saem

## Summary
- Removed macros.TNimSym and macros.TypeKinds

## Details
They are not used anywhere in the code base

399: dialect: remove old case object define r=disruptek a=saem

## Summary
- removed old case object define

NB reset magic is still present


401: stdlib: httpcore ==(string, HttpCode):bool removed r=disruptek a=saem

dropped proc from stdlib, it been deprecatd forever

402: stdlib: removed deprecated module oswalkdir r=disruptek a=saem

functionality has long since been moved to `std/os`

403: stdlib: times, remove deprecated procs r=disruptek a=saem

Removed deprecated constructors and setters for `times.DateTime`

Updated associated broken tests.

405: stdlib: remove deprecated os.existsFile/Dir r=disruptek a=saem

fileExists/dirExists are already present

406: pragma: remove the deprecated unroll pragma r=disruptek a=saem

supposedly it was ignored by the compiler, the fewer pragmas the better.

407: strutils: remove deprecated delete proc r=disruptek a=saem

## Summary

- remove deprecated `delete(var string, int, int)`
- removed associated tests
- updated usage of removed proc in rstgen

409: sequtils: remove deprecated delete proc r=disruptek a=saem

remove deprecated `delete[T](var T, int, int)` and its tests

410: algorithm: remove deprecated reversed proc r=disruptek a=saem

## Summary

- remove deprecated `reversed[T](var openArray[T], int, int): seq[T]`
- removed associated tests


411: math: renamed internal c_frexp2 to c_frexp r=disruptek a=saem

internal proc rename, no impact

412: options: remove deprecated UnpackError r=disruptek a=saem

## Summary

Removed UnpackError, was replaced with UnpackDefect a while back

## Details

Defects in general are a bad idea, but less code is good too

413: lang: remove for loop and case statement macros r=disruptek a=saem

There are better ways to do these sorts of things.

Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants