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

Fix Issue 21443 - scope (failure) with a return breaks safety #14269

Merged
merged 1 commit into from Jul 7, 2022

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Jul 5, 2022

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 5, 2022

Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21443 critical scope (failure) with a return breaks safety

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#14269"

// @@@DEPRECATED_2.112@@@
// Deprecated in 2.100, transform into an error in 2.112
if (sc.os.tok == TOK.onScopeFailure)
rs.deprecation("`return` statements cannot be in `scope(failure)` bodies. Use try-catch blocks for this purpose");
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put "Use try-catch blocks for this purpose" in a deprecationSupplemental.


where an error is circumvented by a return. If a return is indeed desired
in such situations, then the solution is to simply use a try-catch block
for the function body. In addition, `scope(exit)` and `scope(success)` already present this restriction.
Copy link
Contributor

Choose a reason for hiding this comment

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

The "In addition" is not related to to the try-catch block workaround, I would put it in a new paragraph and start with "Note" or something.

@RazvanN7 RazvanN7 changed the base branch from master to stable July 5, 2022 14:22
@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jul 5, 2022

@dkorpel Done + rebased on top of stable.

@RazvanN7 RazvanN7 force-pushed the Issue_21443 branch 2 times, most recently from 6a1f85f to 4473e8a Compare July 5, 2022 15:03
@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Jul 5, 2022

Phobos seems to have some returns in scope(failure) blocks. I wonder why an exception was made for scope(failure). I couldn't find anything in the docs.

cc @WalterBright

@schveiguy
Copy link
Member

The issue is here: https://github.com/dlang/phobos/blob/38243e3716087fbe8cbe364b2383bf73ef73cefa/std/typecons.d#L4908

I think we can replace this with a traditional try/catch(Exception)

@schveiguy
Copy link
Member

schveiguy commented Jul 5, 2022

In other words, I think this has already found a bug in Phobos.

EDIT: oh wait, that's only inside a unittest. Just change the unittest, it's not testing that specific feature of phobos.

@schveiguy
Copy link
Member

Is the documentation updated? Great to see this in there!

@RazvanN7
Copy link
Contributor Author

@schveiguy dlang/dlang.org#3338

@ljmf00
Copy link
Member

ljmf00 commented Jan 10, 2023

@RazvanN7 can you point the rationale out in https://dlang.org/deprecate.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants