-
-
Notifications
You must be signed in to change notification settings - Fork 655
fix Issue 20956 - [DIP1000] @safe defeated by closure capturing ref p… #14364
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* REQUIRED_ARGS: -preview=dip1000 | ||
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/test20956.d(105): Error: function `test20956.forwardDg` cannot close over `ref` variable `c` | ||
| --- | ||
| */ | ||
|
|
||
| // https://issues.dlang.org/show_bug.cgi?id=20956 | ||
|
|
||
| #line 100 | ||
|
|
||
| @safe: | ||
|
|
||
| alias DG = void delegate() @safe; | ||
|
|
||
| DG forwardDg(ref int c) | ||
| { | ||
| return () {assert(c == 42);}; | ||
| } | ||
|
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the compiler infer the closure to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The trouble here is the delegate escapes the function, thereby escaping the reference to c. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, we're returning the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
Uh oh!
There was an error while loading. Please reload this page.