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 20956 - [DIP1000] @safe defeated by closure capturing ref p… #14364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WalterBright
Copy link
Member

…arameter

Very similar to fix for #14363

@dlang-bot
Copy link
Contributor

dlang-bot commented Aug 12, 2022

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

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 "master + dmd#14364"

Comment on lines +16 to +19
DG forwardDg(ref int c)
{
return () {assert(c == 42);};
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the compiler infer the closure to be scope in this case ?
Regardless if it does/can infer it currently, we should not have this error for scope delegate, should we ?

Copy link
Member Author

Choose a reason for hiding this comment

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

ref parameters are implicitly pointers, and are automatically not allowed to escape the function. No need for scope.

The trouble here is the delegate escapes the function, thereby escaping the reference to c.

Copy link
Member

Choose a reason for hiding this comment

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

Right, we're returning the delegate. Can we add a test that not escaping the delegate (the delegate being scope) does not trigger error ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The error is triggered when the delegate is tested to see if a dynamic closure is being created. So the tests for @nogc already do this.

@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#8530

compiler/src/dmd/func.d Show resolved Hide resolved
@WalterBright
Copy link
Member Author

I guess the test suite is going to drip-drip-drip the phobos failings one at a time.

@WalterBright
Copy link
Member Author

Blocked by bugs in Buildkite projects.

@dlang-bot dlang-bot removed the stalled label Apr 22, 2024
@thewilsonator thewilsonator added the dip1000 memory safety with scope, ref, return label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Bug Fix dip1000 memory safety with scope, ref, return stalled
Projects
No open projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants