[D] Fixed a bug in the loop breaking code for directors leading to a superclass implementation erroneously being called.

The situation in which this would previously happen is illustrated in the new "director_alternating" test case. Currently broken for C# and Java.

Thanks to Jimmy Cao for reporting this.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12380 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
David Nadlinger 2011-01-08 21:05:49 +00:00
commit 892caec201
6 changed files with 69 additions and 4 deletions

View file

@ -154,6 +154,7 @@ CPP_TEST_CASES += \
derived_nested \
destructor_reprotected \
director_abstract \
director_alternating \
director_basic \
director_classes \
director_classic \

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,36 @@
// Checks if calls to a method being defined in the base class, not
// overridden in the subclass, but again overridden in a class derived from
// the first subclass are dispatched correctly.
%module(directors="1") director_alternating;
%feature("director") Foo;
%inline %{
struct Foo {
virtual ~Foo() {}
virtual int id() {
return 0;
}
};
struct Bar : Foo {};
struct Baz : Bar {
virtual int id() {
return 2;
}
};
// Note that even though the return value is of type Bar*, it really points to
// an instance of Baz (in which id() has been overridden).
Bar *getBar() {
static Baz baz;
return &baz;
}
// idFromGetBar() obviously is equivalent to getBar()->id() in C++ this
// should be true from the target language as well.
int idFromGetBar() {
return getBar()->id();
}
%}

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,5 @@
from director_alternating import *
id = getBar().id()
if id != idFromGetBar():
raise RuntimeError, "Got wrong id: " + str(id)