$ dmd mixinstruct.d mixinstruct.d(15): function mixinstruct.S.attr (int) does not match parameter types () mixinstruct.d(15): Error: s.attr can only be called on a mutable object, not const(S) mixinstruct.d(15): Error: expected 1 arguments, not 0 mixinstruct.d(15): Error: expression s.attr() is void and has no value $ cat mixinstruct.d ============================================================== template T() { int m_attr; const {int attr() {return m_attr;}} // reader } struct S { mixin T; void attr(int n) {m_attr = n;} // writer } int main() { const S s; int r; r = s.attr(); // why this resolve to the writer? but not the reader? return r; } ==============================================================
On DMD 2.019 Windows, the errors are the same, except at line 14.
This is still an issue in dmd 2.057, tested with the following code: mixin template EagerSingleton() { private this() { instance = this; } private static typeof(this) instance; } class NetworkPacketQueue { mixin EagerSingleton; public this(string bla) { this(); } } void main() { new NetworkPacketQueue("Hey"); }
This is not an issue. http://d-programming-language.org/template-mixin.html > Mixin Scope > > The declarations in a mixin are ‘imported’ into the surrounding scope. If > the name of a declaration in a mixin is the same as a declaration in the > surrounding scope, the surrounding declaration overrides the mixin one: ^^^^^^^^^ If you want to merge overloads, you can add alias declaration to do it. template T() { int m_attr; const {int attr() {return m_attr;}} } struct S { mixin T t; void attr(int n) {m_attr = n;} alias t.attr attr; // Merge overloads } int main() { const S s; int r; r = s.attr(); return r; }
*** Issue 20080 has been marked as a duplicate of this issue. ***