[PHP] Fix handling of overloaded methods/functions where some

return void and others don't - whether this worked or not depended 
on the order they were encountered in (SF#3208299).


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12539 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2011-03-14 12:33:56 +00:00
parent 5d765893ed
commit 72fc8be46c
4 changed files with 24 additions and 3 deletions

View File

@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.3 (in progress)
===========================
2011-03-14: olly
[PHP] Fix handling of overloaded methods/functions where some
return void and others don't - whether this worked or not depended
on the order they were encountered in (SF#3208299).
2011-03-13: klickverbot
[D] Extended support for C++ namespaces (nspace feature).

View File

@ -10,4 +10,14 @@ class B {
int foo(int x) { return 0; }
A foo(const char * y) { return A(); }
};
// Regression test for PHP from SF#3208299 (there bar()'s return type wa
// treated as always void).
void foo(int i) {}
int foo() { return 1; }
int bar() { return 1; }
void bar(int i) {}
%}

View File

@ -7,4 +7,7 @@ $b = new B;
check::equal($b->foo(1), 0, "");
check::classname("A", $b->foo("test"));
check::equal(overload_return_type::foo(), 1, "overload_return_type::foo() should be 1");
check::equal(overload_return_type::bar(), 1, "overload_return_type::bar() should be 1");
?>

View File

@ -1077,6 +1077,8 @@ public:
Hash *ret_types = NewHash();
Setattr(ret_types, d, d);
bool non_void_return = (Cmp(d, "void") != 0);
if (overloaded) {
// Look at all the overloaded versions of this method in turn to
// decide if it's really an overloaded method, or just one where some
@ -1093,6 +1095,7 @@ public:
assert(constructor);
} else if (!Getattr(ret_types, d2)) {
Setattr(ret_types, d2, d2);
non_void_return = non_void_return || (Cmp(d2, "void") != 0);
}
ParmList *l2 = Getattr(o, "wrap:parms");
@ -1504,7 +1507,7 @@ public:
while (last_handled_i < i) {
Printf(prepare, "case %d: ", ++last_handled_i);
}
if (Cmp(d, "void") != 0) {
if (non_void_return) {
if ((!directorsEnabled() || !Swig_directorclass(n)) && !newobject) {
Append(prepare, "$r=");
} else {
@ -1526,7 +1529,7 @@ public:
Printf(prepare, "\t\t");
if (had_a_case)
Printf(prepare, "default: ");
if (Cmp(d, "void") != 0) {
if (non_void_return) {
if ((!directorsEnabled() || !Swig_directorclass(n)) && !newobject) {
Append(prepare, "$r=");
} else {
@ -1672,7 +1675,7 @@ public:
}
}
Printf(output, "%s", prepare);
} else if (Cmp(d, "void") == 0 && !hasargout) {
} else if (!non_void_return && !hasargout) {
if (Cmp(invoke, "$r") != 0)
Printf(output, "\t\t%s;\n", invoke);
} else if (is_class(d)) {