diff --git a/CHANGES.current b/CHANGES.current index eeac578fd..15c1bdff0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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). diff --git a/Examples/test-suite/overload_return_type.i b/Examples/test-suite/overload_return_type.i index e6b3b130a..aa387a108 100644 --- a/Examples/test-suite/overload_return_type.i +++ b/Examples/test-suite/overload_return_type.i @@ -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) {} + %} diff --git a/Examples/test-suite/php/overload_return_type_runme.php b/Examples/test-suite/php/overload_return_type_runme.php index 84979e6a1..4fa19d22a 100644 --- a/Examples/test-suite/php/overload_return_type_runme.php +++ b/Examples/test-suite/php/overload_return_type_runme.php @@ -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"); + ?> diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 1eb9a86de..a304946e7 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -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)) {