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



commit cbda81d37eec11c228d6bba16a55083da92a15e9
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 fe6ffddb5..6822f2a70 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -606,6 +606,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 \
@@ -614,6 +615,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 601145ade..9ce4fa40d 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".printf (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 42f74a10b..d7aeb33bf 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -917,6 +917,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".printf (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]