Bug 277 – Named mixin operator resolution

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-08-03T11:22:26Z
Last change time
2019-05-23T11:57:14Z
Assigned to
Walter Bright
Creator
Jason O'Brien

Comments

Comment #0 by xergen — 2006-08-03T11:22:26Z
template TestMixin(){ void opCall() { } void opCatAssign(uint val) { } } class Test{ mixin TestMixin bar; void foo(){ //bar(); // doesn't work !?!? bar.opCall(); // works //bar ~= 3; // doesn't work bar.opCatAssign(3); // works } } void main(char[][] args){ Test t = new Test(); t.bar ~= 3; // works t.bar(); // works t.bar.opCall(); // works t.foo(); } May seem trivial, but its actually pretty important for some friendly things im working on. Mixin operators can't be called from within the scope using the mixin? Odd :) Thanks. PS. You're my hero Walter.
Comment #1 by xergen — 2006-08-14T00:21:44Z
Also, operator selection doesnt happen with names. for example: template Foo() { void opAddAssign(int x) { } } class Bar { mixin Foo a; mixin Foo b; } Bar b; bar.a += 2; // ambiguouity error bar.a.opAddAssign(2); // works
Comment #2 by bugzilla — 2006-08-15T23:46:20Z
This is not a bug because operator overloading needs an object, and a mixin is not an object. It's working as designed. I've changed this to an enhancement request.
Comment #3 by xergen — 2006-08-16T16:56:22Z
thanks for the workaround Bruno, though I'm afraid that would still be subject to the problems with operator resolution in my comment :( Works great if you've only got one mixin however :) As far as it being an enhancement, I can see your judgement there. But I would still think the second issue is a bug, as it's simply ignoring the mixin name, which doesn't seem to make much sense to me.
Comment #4 by razvan.nitu1305 — 2019-05-23T11:57:14Z
(In reply to Jason O'Brien from comment #3) > thanks for the workaround Bruno, though I'm afraid that would still be > subject to the problems with operator resolution in my comment :( Works > great if you've only got one mixin however :) > > As far as it being an enhancement, I can see your judgement there. But I > would still think the second issue is a bug, as it's simply ignoring the > mixin name, which doesn't seem to make much sense to me. It is not ignoring the name; it is basically trying to do += on an object (the named mixin) that has void type. The named mixin is like a gateway to select the proper method, not an object on which operator overloading can be applied. The name for the mixin has the purpose of being explicitly used when you want to disambiguate, not to be used as an aggregate declaration; changing this may lead to surprising behavior. Closing as invalid.