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 17674 - [REG 2.064] Simultaneous opBinary and opBinaryRight is not rejected #8922
Conversation
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 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 fetch digger
dub run digger -- build "stable + dmd#8922" |
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.
Needs to target stable though.
@thewilsonator Done. |
phobos fails because of this pattern (reduced): struct S
{
int opBinary(string op, T)(T a) { return 1; }
int opBinaryRight(string op, T)(T a) { return 2; }
}
void main()
{
S a, b;
int k = a + b; // opBinary and opBinaryRight both match.
} |
The phobos usage is real opBinary(string op,T)(T b)
if (__traits(compiles, mixin(`get!real`~op~`b`)))
{
return mixin(`get!real`~op~`b`);
}
real opBinaryRight(string op,T)(T a)
if ( __traits(compiles, mixin(`a`~op~`get!real`)) &&
!__traits(compiles, mixin(`get!real`~op~`b`)))
{
return mixin(`a`~op~`get!real`);
} It looks like opBinaryRight should be called only when opBinary fails. So I'm not sure why its getting this deprecation. Ooh, is it a reflexive transformation? |
I'll do up a phobos PR tomorrow if you don't beat me to it. |
@RazvanN7 please rebase. |
I'm going to resuscitate this and see if it fixes anything. |
Hmm, this also breaks taggedalgebraic unittest { // Binary op between two TaggedAlgebraic values
union U { int i; }
alias TA = TaggedAlgebraic!U;
TA a = 1, b = 2;
static assert(is(typeof(a + b) == int)); // <<< Fails
} cc @s-ludwig |
I've pushed a fix and a new version (0.10.13) of taggedalgeraic now. (PR: s-ludwig/taggedalgebraic#21) |
Thanks! |
Still failing for some reason. BTW, I can imagine situations where two independent types have legitimate generic This is also kind of obvious in my attempt to fix the error for |
The problem is that the same Match object is used to check both opBinary and opBinaryRight and the last match will always be taken into account without comparing the result with the previous match.
functionResolve
cannot be used successively with the same Match object if the parameters differ, because the match count will always be reset to 1 when a better one is found.The fix is to use different match objects and then aggregate them accordingly.