Skip to content

Commit

Permalink
fix Issue 16980 - wrong interface called
Browse files Browse the repository at this point in the history
- ensure that class/interface size is finalized before
  determining the interface offsets
  • Loading branch information
MartinNowak committed Dec 29, 2016
1 parent ada011d commit bbd2280
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -1876,9 +1876,15 @@ extern (C++) final class InterfaceDeclaration : ClassDeclaration
//printf("\tX base %s\n", b.sym.toChars());
if (this == b.sym)
{
//printf("\tfound at offset %d\n", b.offset);
if (poffset)
*poffset = b.offset;
{
// Need to determine correct offset if needed.
// https://issues.dlang.org/show_bug.cgi?id=16980
cd.size(loc);
// HACK: using OFFSET_RUNTIME as error placeholder
*poffset = cd.sizeok == SIZEOKdone ? b.offset : OFFSET_RUNTIME;
}
// printf("\tfound at offset %d\n", b.offset);
return true;
}
if (isBaseOf(b, poffset))
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/test16980.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// https://issues.dlang.org/show_bug.cgi?id=16980
interface A { void foo(); }
interface B { void bar(); }
interface AB : A, B {}
class C : AB {
void foo() { assert(false, "Must never be called!"); }
void bar() {}
}

struct T() {
AB ab;
~this() {
ab.bar(); // uses wrong vtable
}
}

T!() tinst; // triggers semantic3 of dtor from Module::semantic(1)

void main()
{
auto dst = T!()(new C);
}

0 comments on commit bbd2280

Please sign in to comment.