dom96 / nimbox

Fork of https://notabug.org/vktec/nimbox
30 stars 4 forks source link

defer not supported in top level #9

Closed jonathanabennett closed 5 years ago

jonathanabennett commented 5 years ago

When attempting to compile any of the examples under nim 0.20, you receive the following error: Error: defer statement not supported at top level

Presumably, this is caused by the defer: nb.shutdown() present in all examples. According to the language manual, these should probably be try, finally statements when located at the top level.

If that is the preferred method, I will submit a pull request rewriting existing examples in that idiom, but it seems like that would be a rather large try block for any non-trivial program.

dom96 commented 5 years ago

No. The manual states that the defer statement is rewritten to this by the compiler. This is either a regression in the compiler or an intended change, so we might need to put all examples in a proc.

dom96 commented 5 years ago

It's actually likely that defer was never supported at the top-level.

jonathanabennett commented 5 years ago

This was kind of a simple-minded approach to solving the problem, but it should do for the examples.

jonathanabennett commented 5 years ago

We can close this issue as I've tested all of the examples.