Thread overview
[Issue 2061] New: wrong vtable call with multiple interface inheritance
Apr 30, 2008
d-bugmail
Nov 24, 2008
d-bugmail
Dec 09, 2008
d-bugmail
May 15, 2009
Shin Fujishiro
May 15, 2009
Shin Fujishiro
May 15, 2009
Walter Bright
April 30, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2061

           Summary: wrong vtable call with multiple interface inheritance
           Product: D
           Version: 1.029
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: schveiguy@yahoo.com


This might be related to http://d.puremagic.com/issues/show_bug.cgi?id=1978

I added Frank and Lars to the CC in case they are interested.

Basically, I think it has to do with a class implementing two interfaces that inherit from the same base interface.

This might be a minimal example:

extern(C) int printf(char*,...);

interface A(V)
{
    int foo();
}

interface B(K, V) : A!(V)
{
    alias A!(V).foo foo; // needed or else A isn't examined to resolve foo()
    int foo(int x);
}

interface C(K, V) : B!(K, V)
{
}

interface D(K, V) : A!(V), C!(K, V)
{
    alias C!(K, V).foo foo; // needed or else A is used to resolve foo

    int bar();
}

class E(K, V) : C!(K, V)
{
    int foo() {printf("foo\n"); return 0;}
    int foo(int x) {printf("foo(int)\n"); return 0;}
    int bar() {printf("bar\n"); return 0;}
}

void main() {
  C!(uint, uint) c = new D!(uint, uint);
  c.foo();
  c.foo(0);
  c.bar();
}

outputs:
foo
bar
bar

The following change to interface D seems to resolve the issue:
interface D(K, V) : C!(K, V), A!(V)
{
    int bar();
}

However, there might be cases where this kind of solution is not possible.


-- 

November 24, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2061


schveiguy@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.029                       |1.036




------- Comment #1 from schveiguy@yahoo.com  2008-11-24 08:46 -------
sheesh, I think I have messed up the example.

Please replace the definition for class E, and the main function with this:

class E(K, V) : D!(K, V)
{
    int foo() {printf("foo\n"); return 0;}
    int foo(int x) {printf("foo(int)\n"); return 0;}
    int bar() {printf("bar\n"); return 0;}
}

void main() {
    D!(uint, uint) d = new E!(uint, uint);
    d.foo();
    d.foo(0);
    d.bar();
}


-- 

December 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2061


schveiguy@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |blocker




------- Comment #2 from schveiguy@yahoo.com  2008-12-09 11:43 -------
Bumped into this again, with a simpler inheritance tree.

extern(C) int printf(char*,...);

interface A
{
    char a();
}

interface B
{
    char b();
}

interface C : A, B
{
    char c();
}

interface D
{
    char d();
}

interface E : C, D
{
    char e();
}

class Foo : E
{
    char a() { return('a'); }
    char b() { return('b'); }
    char c() { return('c'); }
    char d() { return('d'); }
    char e() { return('e'); }
}

void main() {
    auto foo = new Foo;
    E e = foo; D d = foo; C c = foo; B b = foo; A a = foo;
    printf("Foo: %c %c %c %c %c\n", foo.a, foo.b, foo.c, foo.d, foo.e);
    printf("A: %c\n", a.a);
    printf("B: %c\n", b.b);
    printf("C: %c %c %c\n", c.a, c.b, c.c);
    printf("D: %c\n", d.d);
    printf("E: %c %c %c %c %c\n", e.a, e.b, e.c, e.d, e.e);
}

outputs:

Foo: a b c d e
A: a
B: b
C: a b c
D: d
E: a a c d e

Note the incorrect E line.

If I swap around E's base interfaces, so E now becomes:

interface E : D, C
{
    char e();
}

Now the E line is still wrong:

Foo: a b c d e
A: a
B: b
C: a b c
D: d
E: d b c d e

Marking as a blocker.  I don't know how to work around this.


-- 

May 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2061


Shin Fujishiro <rsinfu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rayerd.wiz@gmail.com




--- Comment #3 from Shin Fujishiro <rsinfu@gmail.com>  2009-05-14 20:50:40 PDT ---
*** Issue 2758 has been marked as a duplicate of this issue. ***

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





--- Comment #4 from Shin Fujishiro <rsinfu@gmail.com>  2009-05-14 21:10:49 PDT ---
Created an attachment (id=367)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=367)
This patch should fix the issue.

There is a typo in class.c. The compiler generates wrong vtable due to the typo.

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





--- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com>  2009-05-15 06:56:20 PDT ---
Which compiler version is your patch against?  According to the changelog, 1.045 fixed this issue.  I haven't had time to test it yet, you may want to compare your patch against that fix.

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #6 from Walter Bright <bugzilla@digitalmars.com>  2009-05-15 12:14:26 PDT ---
Fixed dmd 1.045 and 2.030

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