]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report error for non ErrorType in throws
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 23 Oct 2021 13:27:12 +0000 (15:27 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 24 Oct 2021 12:19:20 +0000 (14:19 +0200)
tests/Makefile.am
tests/errors/delegate-throws-no-error-type.test [new file with mode: 0644]
tests/errors/method-throws-no-error-type.test [new file with mode: 0644]
vala/valadelegate.vala
vala/valamethod.vala

index fb5f4f3a1541c0845cb15b49c83c5e6a3ba29e82..77f144ca2b58bb4ff451353fc5aa43216c717d9c 100644 (file)
@@ -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 (file)
index 0000000..e7f29c0
--- /dev/null
@@ -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 (file)
index 0000000..a64890a
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo () throws int {
+}
+
+void main () {
+}
index 83a3415dcd3ca41a10cdec566fe5caf8b1484b14..df21bd4f1707ae53108f59e3faff2d88dc6a10bf 100644 (file)
@@ -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
index 9044233f1b64a36ee8ab93dd5af10d04f941d9f7..b3bb3794d4f1dfb95d7f6dd1ec58ad4966dbcebd 100644 (file)
@@ -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