[vala/0.52] vala: Report error for non ErrorType in throws



commit 5f30679d87a37da71349c1d2c1e03933f6683006
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Oct 23 15:27:12 2021 +0200

    vala: Report error for non ErrorType in throws

 tests/Makefile.am                               | 2 ++
 tests/errors/delegate-throws-no-error-type.test | 6 ++++++
 tests/errors/method-throws-no-error-type.test   | 7 +++++++
 vala/valadelegate.vala                          | 4 ++++
 vala/valamethod.vala                            | 4 ++++
 5 files changed, 23 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fb5f4f3a1..77f144ca2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -624,6 +624,7 @@ TESTS = \
        errors/catch-in-finally.vala \
        errors/catch-no-error-type.test \
        errors/default-gtype.vala \
+       errors/delegate-throws-no-error-type.test \
        errors/errors.vala \
        errors/errorcode.vala \
        errors/errordomain.vala \
@@ -632,6 +633,7 @@ TESTS = \
        errors/invalid-type-check.test \
        errors/loops.vala \
        errors/method-throws.vala \
+       errors/method-throws-no-error-type.test \
        errors/unhandled.vala \
        errors/bug567181.vala \
        errors/bug579101.vala \
diff --git a/tests/errors/delegate-throws-no-error-type.test b/tests/errors/delegate-throws-no-error-type.test
new file mode 100644
index 000000000..e7f29c0e0
--- /dev/null
+++ b/tests/errors/delegate-throws-no-error-type.test
@@ -0,0 +1,6 @@
+Invalid Code
+
+delegate void FooFunc () throws int;
+
+void main () {
+}
diff --git a/tests/errors/method-throws-no-error-type.test b/tests/errors/method-throws-no-error-type.test
new file mode 100644
index 000000000..a64890ac6
--- /dev/null
+++ b/tests/errors/method-throws-no-error-type.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo () throws int {
+}
+
+void main () {
+}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index 83a3415dc..df21bd4f1 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -325,6 +325,10 @@ public class Vala.Delegate : TypeSymbol, Callable {
 
                if (error_types != null) {
                        foreach (DataType error_type in error_types) {
+                               if (!(error_type is ErrorType)) {
+                                       error = true;
+                                       Report.error (error_type.source_reference, "`%s' is not an error 
type", error_type.to_string ());
+                               }
                                error_type.check (context);
 
                                // check whether error type is at least as accessible as the delegate
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 9044233f1..b3bb3794d 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -924,6 +924,10 @@ public class Vala.Method : Subroutine, Callable {
 
                if (error_types != null) {
                        foreach (DataType error_type in error_types) {
+                               if (!(error_type is ErrorType)) {
+                                       error = true;
+                                       Report.error (error_type.source_reference, "`%s' is not an error 
type", error_type.to_string ());
+                               }
                                error_type.check (context);
 
                                // check whether error type is at least as accessible as the method


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