Thread overview
[Issue 3706] New: delegates of interfaces with multiple inheritance fail
Jan 14, 2010
Fawzi Mohamed
Jan 14, 2010
Fawzi Mohamed
Jan 14, 2010
Fawzi Mohamed
Jan 15, 2010
Leandro Lucarella
Jul 22, 2010
Don
Jul 22, 2010
Don
Jul 25, 2010
Walter Bright
January 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706

           Summary: delegates of interfaces with multiple inheritance fail
           Product: D
           Version: 1.054
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: fawzi@gmx.ch


--- Comment #0 from Fawzi Mohamed <fawzi@gmx.ch> 2010-01-14 12:42:31 PST ---
Created an attachment (id=550)
an example of the bug

Delegates of an interface that refer to methods in sub interfaces that are not the first one fail.

Somehow when done through ThreadLocal variables the bug is slightly different (nothing seems to be called), whereas the other examples that I show another method get called.

I set it as major because it is a subtle bug that took me very long to track
down, its effects a similar to memory pollution...
This is a bug in both 1.047 and 1.055

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706


Fawzi Mohamed <fawzi@gmx.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
    Attachment #550|application/octet-stream    |text/d-source
          mime type|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706



--- Comment #1 from Fawzi Mohamed <fawzi@gmx.ch> 2010-01-14 12:58:44 PST ---
Created an attachment (id=551)
a shorter example

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706


Leandro Lucarella <llucax@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
    Attachment #551|application/octet-stream    |text/d-source
          mime type|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706



--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-07-22 12:20:12 PDT ---
Here's a slightly reduced test case.
--------------
interface I{
    void h();
}
interface K{
    void f();
}

interface J:I,K {}

class A:J{
    void f(){ }
    void h(){ }
}

void main(){
    auto a = new A();
    J b = a;
    K c = a;
    assert(&b.f == &c.f); // fails: &b.f returns &a.h.
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Version|1.054                       |D1 & D2
         OS/Version|Mac OS X                    |All


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-07-22 13:55:22 PDT ---
The problem lies in delegate expressions formed from interfaces. We need to
ensure that the correct interface is used, otherwise the vtblIndex will refer
to the wrong one.
Applies to both D1 and D2.

PATCH: expression.c, not yet fully tested in the test suite. Maybe this patch should be made in getRightThis() instead?

Expression *DelegateExp::semantic(Scope *sc)
{
#if LOGSEMANTIC
    printf("DelegateExp::semantic('%s')\n", toChars());
#endif
    if (!type)
    {
        e1 = e1->semantic(sc);
        type = new TypeDelegate(func->type);
        type = type->semantic(loc, sc);
        AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration();
        if (func->needThis())
            e1 = getRightThis(loc, sc, ad, e1, func);
+        if (ad && ad->type != e1->type)
+        {   // A downcast is required for interfaces
+            e1 = new CastExp(loc, e1, ad->type);
+            e1 = e1->semantic(sc);
+        }
    }
    return this;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3706


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> 2010-07-24 19:10:38 PDT ---
http://www.dsource.org/projects/dmd/changeset/587

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