www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3694] New: Template this parameters don't work with operator overloads

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

           Summary: Template this parameters don't work with operator
                    overloads
           Product: D
           Version: 2.036
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tomeksowi gmail.com



PST ---
Testcase:

class A {
    int a;
    This opAssign(this This)(int a) {
        this.a = a;
        return this;
    }
}

void main() {
    A aa = new A;
    aa = 4;   // oops!
}

Error: template test.A.opAssign(this This) does not match any function template
declaration
Error: template test.A.opAssign(this This) cannot deduce template function from
argument types !()(int)

-----------------------------------------------

The testcase should compile. Problem is that when operator overloads are used,
template this parameters are not inferred. I suspect it's like that for all
operator overloads (I tested only for assign and add, though).

When you call the operator functions explicitly, aa.opAssign(4), it compiles.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3694


gareth.charnock gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gareth.charnock gmail.com



I can confirm this bug is still present in DMD 2.040. Test case used:


struct ddouble(int l,int m /*other SI dimensions would go here*/) {
    this(double _val) {val=val;}
    ddouble!(l+l2,m+m2) opMult(int l2,int m2)(ddouble!(l2,m2) oprand) {
        return ddouble!(l+l2,m+m2)(val*oprand.val);
    }
    ddouble!(l+l2,m+m2) mult(int l2,int m2)(ddouble!(l2,m2) oprand) {
        return ddouble!(l+l2,m+m2)(val*oprand.val);
    }
    /* /,-,+ operators would go here */
    double val;
};

void main() {
    ddouble!(1,0) length=ddouble!(1,0)(1.0);
    ddouble!(0,1) mass  =ddouble!(0,1)(1.0);

    auto t2=length.mult(mass);  //Works
    auto t3=length*mass;        //Error
}
testcase.d(28): Error: incompatible types for ((length) * (mass)):
'ddouble!(1,0)' and 'ddouble!(0,1)'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 04 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3694




Bug appears to be fixed in DMD 2.041. Both test cases compile fine now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3694


Tomasz SowiƄski <tomeksowi gmail.com> changed:

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



PST ---

 Bug appears to be fixed in DMD 2.041. Both test cases compile fine now.
Also works here. I'm marking as fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 13 2010