www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7833] New: Regression(2.059 Beta): struct opEquals broken

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

           Summary: Regression(2.059 Beta): struct opEquals broken
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com



17:35:31 PDT ---
struct Foo
{
    const bool opEquals(ref const Foo b)
    {
        return true;
    }
}

void main()
{
    assert( Foo() == Foo() );
}

dmd testOpCmp.d
testOpCmp.d(11): Error: function testOpCmp.Foo.opEquals (ref const(Foo) b) is not callable using argument types (Foo) testOpCmp.d(11): Error: Foo() is not an lvalue It works if Foo is changed to a class. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 05 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7833


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
Actually, I don't believe that this is a bug. With this release, Foo() has been
fixed so that it's not an lvalue. Previously Foo() would have been considered
an lvalue but a Foo returned from a function would not making it so that

assert(foo == Foo());

worked by

assert(foo == getFoo());

did not. Many of us considered it incredibly inconsistent to treat struct
literals as lvalues. They're temporaries and don't represent variables or
places in memory at all. So, they shouldn't be lvalues. And not they're not, so
your opEquals doesn't work.

Given that auto ref currently only works with templates, I believe that the
correct solution for this is to then declare 2 overloads of opEquals.

struct Foo
{
    bool opEquals(ref const Foo b) const
    {
        return true;
    }

    bool opEquals(Foo b) const
    {
        return true;
    }
}

One will work with lvalues and avoid copying them, whereas the other will work
with rvalues. I believe that when Kenji fixed it so that struct literals aren't
lvalues, he also went into Phobos and fixed it so that all structs which define
opEquals define both overloads of opEquals. You'll need to do the same.

So yes, this change breaks code, but as I understand it, it's a bug fix, not a
regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7833


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |
            Summary|Regression(2.059 Beta):     |[2.059 Beta] Changelog
                   |struct opEquals broken      |should clearly mention
                   |                            |struct
                   |                            |literal/opCmp/opEquals
                   |                            |changes



19:18:05 PDT ---
I see. I had tried removing the "const" and it still failed, but removing both
"const" AND "ref" does indeed work.

I'm going to remove the "rejects-valid" and leave this open (with a new title)
because I think it's very important the changelog clearly mentions this in the
"Changed Features", Ie that struct literals are no longer lvalues *and* that
this means opCmp/opEquals/etc now need a non-const non-ref overload.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7833




00:10:57 PDT ---
It also needs to mention this stuff in the "Operator Overloading" page of the
documentation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7833




23:17:14 PDT ---
The changes also need to be reflected on the "Associative Arrays" page with
toHash.

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


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
On 2.059, the test compiles, but now, swapping "struct" with "class", we get:

PS E:\DigitalMars\dmd2\samples> rdmd bug.d
bug.d(16): Error: no property 'opCall' for type 'bug.Foo'
bug.d(16): Error: no property 'opCall' for type 'bug.Foo'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7833


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com



10:30:02 PDT ---
Class instances are created with new or emplace function. Foo() won't work for
classes by design.

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