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

Add language specification for finally clause #256

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Mar 18, 2022

Summary

This is an attempt at expanding the specification with tests for everything finally related. It's not in a mergeable state yet, but I thought that it might be useful already.


The additions to t06_procedure_calls.nim are more or less structured, while t07_finally.nim is currently more of a dumping ground for various test cases than anything else.

To-do:

  • add more tests for interactions between finally and both {.inline.} and {.closure.} iterators
  • add documentation
  • re-organize test cases
  • file issues for test cases that fail / put them into separate files with "knownIssue" markings
  • there are still missing cases
  • it might make sense to add some kind of mini-DSL via macros, in order to write the test cases in a way that makes them easier to comprehend and modify. They're mostly just copy-and-pasted right now.
  • a macro or script that auto-generates lots of different permutations might also be a good idea

Copy link
Collaborator

@haxscramper haxscramper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion in #main - the closest we got to the "everyone sort of agrees it is the way things should be" is (mostly per @alaviss, and I think I can probably agree to it as well).

  • If try body exit normally and finally exit for reason R, the block exit for reason R
  • If try body exit for reason S and finally exit normally, the block exit for reason S
  • If try body exit abruptly for reason S and finally exit abruptly for reason R
    • If S is an unhandled exception and R is not an unhandled exception, the block exit for reason S
    • If S and R are unhandled exceptions, R is chained to S and the block exit for reason R -- R is chained to S (S will be the new toplevel exception in chain)
    • Otherwise, the block exit for reason R and S is discarded

This would allow avoiding dropping exceptions while mostly maintaining the "finally takes priority" behavior that we have now.

NOTE: it is just a tl;dr to keep the context in place - the PR is perfectly fine as it is now, I think.

yield 1

var it = iter
# TODO: what should happen here?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per current behavior - yield should take priority, like any other 'jump' in finally.
Per recent discussion on how things should be implemented later on - raise should take priority.

@haxscramper haxscramper added the spec Specification tests edit or formal specification required. label Nov 20, 2022
@haxscramper haxscramper self-assigned this Nov 25, 2022
@haxscramper
Copy link
Collaborator

I think I can work on this later on, after #476 and #135 are merged and general test cleanup is complete.

@zerbina
Copy link
Collaborator Author

zerbina commented Nov 25, 2022

Sure, feel free to take this over. I believe the to-do list is still up-to-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec Specification tests edit or formal specification required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants