www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2157] New: mixin struct, function overload

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2157

           Summary: mixin struct, function overload
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: someanon yahoo.com


$ 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;
}

==============================================================


-- 
Jun 20 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2157


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |rejects-valid
         OS/Version|Linux                       |All




------- Comment #1 from smjg iname.com  2008-11-24 06:45 -------
On DMD 2.019 Windows, the errors are the same, except at line 14.


-- 
Nov 24 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2157


pompei2 gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pompei2 gmail.com


--- Comment #2 from pompei2 gmail.com 2011-12-17 17:05:10 PST ---
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");
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 17 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2157


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-12-17 18:12:05 PST ---
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; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 17 2011