[vala/0.52] vala: Fix signals with generic return
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52] vala: Fix signals with generic return
- Date: Mon, 29 Nov 2021 12:32:09 +0000 (UTC)
commit b213cfc71eb989538255023bde689f9def9e0dbd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Nov 26 15:34:40 2021 +0100
vala: Fix signals with generic return
In addition to 36999b5ffd63cc56a8648791b02bf07e7da88077
codegen/valagsignalmodule.vala | 4 ++--
tests/Makefile.am | 1 +
tests/objects/signals-generic-return.vala | 39 +++++++++++++++++++++++++++++++
vala/valasignal.vala | 7 ++++--
4 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 126e78a44..17b681365 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -242,7 +242,7 @@ public class Vala.GSignalModule : GObjectModule {
CCodeFunctionCall fc;
- if (return_type.type_symbol != null || return_type is ArrayType) {
+ if (return_type.type_symbol != null || return_type is ArrayType || return_type is
GenericType) {
ccode.add_declaration (get_value_type_name_from_type_reference (return_type), new
CCodeVariableDeclarator ("v_return"));
fc = new CCodeFunctionCall (new CCodeIdentifier ("g_return_if_fail"));
@@ -318,7 +318,7 @@ public class Vala.GSignalModule : GObjectModule {
}
fc.add_argument (new CCodeIdentifier ("data2"));
- if (return_type.type_symbol != null || return_type is ArrayType) {
+ if (return_type.type_symbol != null || return_type is ArrayType || return_type is
GenericType) {
ccode.add_assignment (new CCodeIdentifier ("v_return"), fc);
CCodeFunctionCall set_fc;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9b4feb1cd..a2522ce6c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -532,6 +532,7 @@ TESTS = \
objects/signals-dynamic-lambda-handler.test \
objects/signals-error-marshal.vala \
objects/signals-fundamental-return.vala \
+ objects/signals-generic-return.vala \
objects/signals-gobject-return.vala \
objects/signals-lambda-delegate.vala \
objects/signals-prototype-access.vala \
diff --git a/tests/objects/signals-generic-return.vala b/tests/objects/signals-generic-return.vala
new file mode 100644
index 000000000..410cdc789
--- /dev/null
+++ b/tests/objects/signals-generic-return.vala
@@ -0,0 +1,39 @@
+class Foo<G,T> : Object {
+ public signal G on_foo ();
+ public signal T on_bar ();
+}
+
+int cb_foo () {
+ return 23;
+}
+
+string cb_bar () {
+ return "foo";
+}
+
+void main () {
+ {
+ var foo = new Foo<int,string> ();
+ foo.on_foo.connect (() => {
+ return 42;
+ });
+ foo.on_bar.connect (() => {
+ return "bar";
+ });
+
+ var bar = foo.on_foo ();
+ assert (bar == 42);
+ var bar2 = foo.on_bar ();
+ assert (bar2 == "bar");
+ }
+ {
+ var foo = new Foo<int,string> ();
+ foo.on_foo.connect (cb_foo);
+ foo.on_bar.connect (cb_bar);
+
+ var bar = foo.on_foo ();
+ assert (bar == 23);
+ var bar2 = foo.on_bar ();
+ assert (bar2 == "foo");
+ }
+}
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index 8e805d682..ffd5a760a 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -115,7 +115,7 @@ public class Vala.Signal : Symbol, Callable {
generated_delegate.sender_type = sender_param_type;
- bool is_generic = false;
+ bool is_generic = actual_return_type.is_generic ();
foreach (Parameter param in parameters) {
var actual_param = param.copy ();
@@ -133,8 +133,11 @@ public class Vala.Signal : Symbol, Callable {
generated_delegate.add_type_parameter (new TypeParameter (type_param.name,
type_param.source_reference));
}
- // parameter types must refer to the delegate type parameters
+ // return type and parameter types must refer to the delegate type parameters
// instead of to the class type parameters
+ foreach (var type_param in generated_delegate.get_type_parameters ()) {
+ actual_return_type.replace_type_parameter (cl.get_type_parameters ().get
(cl.get_type_parameter_index (type_param.name)), type_param);
+ }
foreach (var param in generated_delegate.get_parameters ()) {
foreach (var type_param in generated_delegate.get_type_parameters ()) {
param.variable_type.replace_type_parameter (cl.get_type_parameters
().get (cl.get_type_parameter_index (type_param.name)), type_param);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]