www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3706] New: delegates of interfaces with multiple inheritance fail

reply d-bugmail puremagic.com writes:
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



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: -------
Jan 14 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3706


Fawzi Mohamed <fawzi gmx.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

          mime type|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3706




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: -------
Jan 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3706


Leandro Lucarella <llucax gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

          mime type|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3706




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: -------
Jul 22 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 22 2010
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 24 2010