-
-
Notifications
You must be signed in to change notification settings - Fork 609
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 20704 - -preview=rvaluerefparam does not work with init as default parameter #12413
Conversation
|
Thanks for your pull request and interest in making D better, @nordlow! 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 + dmd#12413" |
|
tests? |
Done |
|
please include the description of the issue in the commit message so it shows up in the log |
In this case the title doesn't quite match what is being corrected. The correction in this PR involves default parameters in general. |
|
In which case the test case should test for more that just |
Are you satisfied with compilable tests now, @thewilsonator? |
src/dmd/typesem.d
Outdated
| if (isRefOrOut && !isAuto && | ||
| !(global.params.previewIn && (fparam.storageClass & STC.in_))) | ||
| !(global.params.previewIn && (fparam.storageClass & STC.in_)) && | ||
| !(global.params.rvalueRefParam)) | ||
| e = e.toLvalue(sc, e); |
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.
Actually could you change this to
if (isRefOrOut && !isAuto &&)
{
if ((!(global.params.previewIn && (fparam.storageClass & STC.in_))) ||
!(global.params.rvalueRefParam))
{
e = e.toLvalue(sc, e);
if (e.op == TOK.error)
errorSupplimental(e.loc, "use `-preview=in` or `preview=rvaluerefparam`"
}
}note || not &&
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.
I don't see the logic in using || instead of &&. Using || makes my compilable test fail.
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.
I've updated the condition accordingly with the exception of leaving the above mentioned && unchanged. Along with and updated expected message for fail_compilation.
|
also cc @Geod24 as this touches |
|
When this is merged what's keeping us from activating |
|
Note you will also have to update the error messages in |
Thanks. Done. |
|
Are we satisfied with error message struct and class types being respectively? If so, ok to modify error message to ? If we do this I believe we should modify all other messages beginning with |
Probably the fact that the DIP was rejected. IMO this switch should be removed but ALAS @TurkeyMan uses it. |
| if (e.op == TOK.error) | ||
| errorSupplemental(e.loc, "use `-preview=in` or `preview=rvaluerefparam`"); |
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.
Don't think we should recommend those -preview switch as neither have been approved by our BDFLs.
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.
Ok with me to remove it. What's the DIP-number for it? And why was this added to dmd if it was rejected? Is there a plan for a substitute DIP?
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.
I'd rather leave this in.
https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1016.md
reject because
void fun(ref int x);
fun(10);which is disallowed by the current implementation. The current implementation was done because @TurkeyMan quite rightly complained that the review process was not good and that there is utility in the feature.
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.
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.
@thewilsonator : I would appreciate if you gave me the time to reply to this. Whether or not you or someone else feels the review process wasn't good doesn't change the fact that the BDFLs decision have been expressed clearly and this is somewhat going against it.
And regarding -preview=in, as much as I want to recommend it to people I will not do it through the compiler as long as we haven't reached a consensus on it.
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.
Is the problem the fact that mutable references also can be passed rvalues? Like in
struct S {}
void e(const ref int x) {}
void f(ref int x) {}
void fS(ref S x) {}
void g(const ref shared long x) {}
unittest {
e(10); // ok
f(10); // ok with -preview=rvaluerefparam, error otherwise
fS(S()); // ok with -preview=rvaluerefparam, error otherwise
g(10L); // always error
}. Why not, for now, disallow a mutable reference parameter from being passed an r-value? C++ does this; for instance
void f(int& x) { x = 3; }
int main() { f(3); }fails as
<stdin>:2:16: error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
<stdin>:1:13: note: initializing argument 1 of ‘void f(int&)’
Ping, @Geod24
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.
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.
I agree. It doesn't seem to be that difficult to adjust the corrnercases for -refvaluerefparam and make it activate by default. This is such a cornercase.
This PR fixes build errors with defaulted ref parameters in general, not just the ref parameters defaulted to
T.init.