Skip to content

Commit

Permalink
Merge pull request #4144 from rainers/issue_14966
Browse files Browse the repository at this point in the history
fix issue 14966: misuse of super
  • Loading branch information
DmitryOlshansky committed Apr 5, 2016
2 parents adc44c4 + 7cdd709 commit 0b99239
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions std/xml.d
Expand Up @@ -599,11 +599,9 @@ class Document : Element
override bool opEquals(Object o)
{
const doc = toType!(const Document)(o);
return
(prolog != doc.prolog ) ? false : (
(super != cast(const Element)doc) ? false : (
(epilog != doc.epilog ) ? false : (
true )));
return prolog == doc.prolog
&& (cast()this).Element.opEquals(cast()doc)
&& epilog == doc.epilog;
}

/**
Expand All @@ -621,14 +619,13 @@ class Document : Element
override int opCmp(Object o)
{
const doc = toType!(const Document)(o);
return
((prolog != doc.prolog )
? ( prolog < doc.prolog ? -1 : 1 ) :
((super != cast(const Element)doc)
? ( cast()super < cast()cast(const Element)doc ? -1 : 1 ) :
((epilog != doc.epilog )
? ( epilog < doc.epilog ? -1 : 1 ) :
0 )));
if (prolog != doc.prolog)
return prolog < doc.prolog ? -1 : 1;
if (int cmp = (cast()this).Element.opCmp(cast()doc))
return cmp;
if (epilog != doc.epilog)
return epilog < doc.epilog ? -1 : 1;
return 0;
}

/**
Expand All @@ -639,7 +636,7 @@ class Document : Element
*/
override size_t toHash() @trusted
{
return hash(prolog, hash(epilog, (cast()super).toHash()));
return hash(prolog, hash(epilog, (cast()this).Element.toHash()));
}

/**
Expand All @@ -653,6 +650,24 @@ class Document : Element
}
}

unittest
{
// https://issues.dlang.org/show_bug.cgi?id=14966
auto xml = `<?xml version="1.0" encoding="UTF-8"?><foo></foo>`;

auto a = new Document(xml);
auto b = new Document(xml);
assert(a == b);
assert(!(a < b));
int[Document] aa;
aa[a] = 1;
assert(aa[b] == 1);

b ~= new Element("b");
assert(a < b);
assert(b > a);
}

/**
* Class representing an XML element.
*
Expand Down

0 comments on commit 0b99239

Please sign in to comment.