[vala/staging: 2/4] vala: Improve error message for invalid handler of dynamic signal




commit 8db3f8a67c8881f045b9656fd7cdb2cdda2e60d6
Author: Lorenz Wildberg <lorenz wild-fisch de>
Date:   Fri Oct 29 11:50:30 2021 +0100

    vala: Improve error message for invalid handler of dynamic signal

 tests/Makefile.am                                 | 1 +
 tests/objects/signals-dynamic-lambda-handler.test | 8 ++++++++
 vala/valamemberaccess.vala                        | 6 +++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cee1f693b..d0062f879 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -534,6 +534,7 @@ TESTS = \
        objects/signals-delegate.vala \
        objects/signals-delegate-parameter.vala \
        objects/signals-dymanic-invalid-handler.test \
+       objects/signals-dynamic-lambda-handler.test \
        objects/signals-error-marshal.vala \
        objects/signals-fundamental-return.vala \
        objects/signals-gobject-return.vala \
diff --git a/tests/objects/signals-dynamic-lambda-handler.test 
b/tests/objects/signals-dynamic-lambda-handler.test
new file mode 100644
index 000000000..ae86c9f1c
--- /dev/null
+++ b/tests/objects/signals-dynamic-lambda-handler.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+void main () {
+       dynamic Object? foo = null;
+       foo.on_bar.connect ((baz) => {
+               // lambdas are not allowed
+       });
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 5be3fa0da..f3b87994a 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -489,7 +489,11 @@ public class Vala.MemberAccess : Expression {
                                                        unowned MemberAccess? arg = s.handler as MemberAccess;
                                                        if (arg == null || !arg.check (context) || 
!(arg.symbol_reference is Method)) {
                                                                error = true;
-                                                               Report.error (s.handler.source_reference, 
"Invalid handler for `%s'", s.get_full_name ());
+                                                               if (s.handler is LambdaExpression) {
+                                                                       Report.error 
(s.handler.source_reference, "Lambdas are not allowed for dynamic signals");
+                                                               } else {
+                                                                       Report.error 
(s.handler.source_reference, "Cannot infer call signature for dynamic signal `%s' from given expression", 
s.get_full_name ());
+                                                               }
                                                        }
                                                }
                                                s.access = SymbolAccessibility.PUBLIC;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]