Bug 19130 – Disabling opAssign in aliasing struct hides all opAssigns in subtyped alias

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2018-07-30T21:31:02Z
Last change time
2018-07-31T20:44:08Z
Assigned to
No Owner
Creator
Ali Ak

Comments

Comment #0 by ali.akhtarzada — 2018-07-30T21:31:02Z
struct A { void opAssign(int) {} } struct B { A a; alias a this; @disable void opAssign(string) {}; } void main() { B b; b = 3; } Produces Error: function `onlineapp.B.opAssign` is not callable because it is annotated with @disable This kind of functionality is very useful for proxy types that have an alias T this, but want to disable copying (i.e this(this) and copy opAssign)
Comment #1 by schveiguy — 2018-07-31T20:44:08Z
Works as designed. As I mentioned in the forum thread, when you override one overload of a base function, you override them all. With classes, you can alias in the base class definitions of the function, but with alias this, that is not an option (there will be a `this` type mismatch). The workaround is to forward the other overloads back to the base. e.g.: auto opAssign(int x) { return a.opAssign(x); }