D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3983 - Regression(2.037): struct with == can't be member of struct with template opEquals
Summary: Regression(2.037): struct with == can't be member of struct with template opE...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: diagnostic, patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2010-03-18 02:48 UTC by Don
Modified: 2015-06-09 01:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2010-03-18 02:48:16 UTC
struct Fug
{
    bool opEquals(ref const Fug y) const {
        return false;
    }
}

struct Fig
{  // line 29
   Fug f;   
   bool opEquals(Tdummy=void)(ref const Fig y) const {
      return false;
   }
   
   bool opEquals(T: int)(T y) const {
      return false;
   }
}

void main() {
  Fig fx, fy;
  if (fx==2) {}
}
---
And the error message is nonsense:

bug.d(29): Error: function bug.Fig.opEquals conflicts with template bug.Fig.opEq
uals(Tdummy = void) at bug.d(31)

Worked in 2.036.
--------
// Workaround is to change Fug opEquals to:
    bool opEquals(Tdummy=void)(ref const Fug y) const
Comment 1 Don 2010-06-11 02:36:12 UTC
Problem is in struct.c, StructDeclaration::semantic(), line 497:
it tries to find an opEquals() function, and if not present, it builds one.
It should look for a template opEquals() also. If there's a template opEquals,
then creating a non-template opEquals will inevitably cause a naming conflict.


        Dsymbol *s = search_function(this, Id::eq);
        FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL;
+        TemplateDeclaration *td = s ? s->isTemplateDeclaration() : NULL;
        if (fdx)
        {
            eq = fdx->overloadExactMatch(tfeqptr);
            if (!eq)
                fdx->error("type signature should be %s not %s", tfeqptr->toChars(), fdx->type->toChars());
        }

-        if (!eq)
+        if (!eq && !td)
            eq = buildOpEquals(sc2);
Comment 2 Walter Bright 2010-06-27 23:15:27 UTC
http://www.dsource.org/projects/dmd/changeset/564