-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Issue 23101 - [std.sumtype] canMatch does not account ref #8457
Conversation
The template `canMatch` does not account for `ref`. The template `valueTypes` stores all types of the member values and uses SumTypes's `get` function, which returns a `ref`. However, ref does not persist and the type is not sent to `canMatch` as a `ref`. Because of this, when matching, `canMatch` will fail as it will test for a copy, and returning a reference of that value results in escaping it. Fix Issue 23101 Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
|
Thanks for your pull request and interest in making D better, @iK4tsu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8457" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good. CC @pbackus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test could be a little cleaner, but looks good overall. Thanks for catching this!
|
I also used |
d7fac1c to
5f67888
Compare
…ence Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
5f67888 to
d39c4ea
Compare
Previously, canMatch would reject these handlers because calling them would escape a reference to 'args' from the lambda '(Ts args) => handler(args)'. Making 'args' a ref parameter allows the compiler to instead infer it as 'return ref' in this situation. Dlang issue: https://issues.dlang.org/show_bug.cgi?id=23101 Phobos PR: dlang/phobos#8457
| // issue: https://issues.dlang.org/show_bug.cgi?id=23101 | ||
| @safe unittest | ||
| { | ||
| static assert(!__traits(compiles, () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the expected compile error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, it's:
Error: returning
match(st)escapes a reference to local variablest
Which is also an error in @system functions
We can safely assume all
Tsvalues can be tested withrefbecausegetalways returns byref.