Bug 4258 – "auto ref" doesn't work in one or more cases
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-06-01T10:11:00Z
Last change time
2011-07-01T19:52:49Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-06-01T10:11:15Z
I think this is a correct D2 program:
struct Vec {
Vec opOpAssign(string Op)(auto ref Vec other) if (Op == "+=") {
return this;
}
Vec opBinary(string Op:"+")(Vec other) {
Vec result;
return result += other;
}
}
void main() {
Vec v;
v += Vec() + Vec(); // line 12
}
But DMD v2.046 prints:
temp.d(12): Error: function temp.Vec.opOpAssign!("+=").opOpAssign (auto ref Vec other) is not callable using argument types (Vec)
temp.d(12): Error: (Vec()).opBinary((Vec())) is not an lvalue
Comment #1 by andrej.mitrovich — 2010-08-30T06:42:08Z
I get different errors with 2.048:
bug4258.d(7): Error: 'result' is not a scalar, it is a Vec
bug4258.d(7): Error: 'result' is not of arithmetic type, it is a Vec
bug4258.d(7): Error: 'other' is not of arithmetic type, it is a Vec
bug4258.d(12): Error: template instance bug4258.Vec.opBinary!("+") error instantiating
bug4258.d(12): Error: 'v' is not a scalar, it is a Vec
(In reply to comment #3)
Thanks for your merging.
> (In reply to comment #2)
> > Patch create and send pull request:
> > https://github.com/D-Programming-Language/dmd/pull/51
>
> With the patch, the error is the same as in Andrej's comment.
Original test code is now invalid, because the template string argument of opOpAssign is just "+", not "+=".
I just send pull request for adding test case. Please merge it.
https://github.com/D-Programming-Language/dmd/pull/182