Thread overview
[Issue 3367] New: Regression: assignment at declaration no longer supports opAssign or ctor overloads
Oct 06, 2009
Rob Jacques
[Issue 3367] Regression: struct initialization no longer supports ctor overloads
Oct 06, 2009
Don
Oct 06, 2009
Sobirari Muhomori
Oct 29, 2009
Don
Nov 04, 2009
Leandro Lucarella
Nov 06, 2009
Walter Bright
October 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367

           Summary: Regression: assignment at declaration no longer
                    supports opAssign or ctor overloads
           Product: D
           Version: 2.033
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: sandford@jhu.edu


--- Comment #0 from Rob Jacques <sandford@jhu.edu> 2009-10-05 20:45:10 PDT ---
In DMD 2.032, when a struct was assigned to at it's declaration point, opAssign overloads were called if other alternative were not available. In DMD 2.033, neither opAssign or ctor overloads are called, only static opCall works

struct Foo {
    int x;
//    static opCall(int v) { // Un-comment this and the below works
//        Foo f;
//        f.x = v;
//        return f;
//    }
    this(int v){ x = v; }
    void opAssign(int v){
        x = v;
        return this;
    }
}

void main(char[][] args) {

    int y = 5;
    Foo f = y;  // fails
    f = y;      // okay
    f = Foo(y); // okay

}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
            Summary|Regression: assignment at   |Regression: struct
                   |declaration no longer       |initialization no longer
                   |supports opAssign or ctor   |supports ctor overloads
                   |overloads                   |


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2009-10-06 01:14:23 PDT ---
My fault. This is a consquence of the fix to bug 2702. Previously it used to accept any old garbage inside a struct initializer; now it only accepts static opCall. It should definitely allow constructors as well.

Based on my reading of the spec, the fact that opAssign used to work seems to
have been a bug:
"assignment is defined as copying the contents of one object over another,
already initialized, type" (struct.html)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367


Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2009-10-29 12:58:44 PDT ---
PATCH: declaration.c, line 1094.
            {
            /* Look for opCall
             * See bugzilla 2702 for more discussion
             */
            Type *ti = ei->exp->type->toBasetype();
------- ADD THIS CODE:            
            // Look for ctor
            if (sd->ctor &&
                /* Initializing with the same type is done differently
                 */
                !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc)))
{
               // Rewrite as e1.call(arguments)
                Expression * eCall = new DotIdExp(loc, e1, Id::ctor);
                ei->exp = new CallExp(loc, eCall, ei->exp);
            }
            else
-----------
            // Don't cast away invariant or mutability in initializer
            if (search_function(sd, Id::call) &&

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 04, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367


Leandro Lucarella <llucax@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax@gmail.com


--- Comment #3 from Leandro Lucarella <llucax@gmail.com> 2009-11-04 06:39:53 PST ---
SVN commit: http://www.dsource.org/projects/dmd/changeset/235

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3367


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2009-11-06 11:34:23 PST ---
Fixed dmd 2.036

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------