]> 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:57:31 +0000 (14:57 +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 fe6ffddb533161c1c4fe9f5008531838bbd32aa9..6822f2a7078b69e25e955be1c0947053d376a73a 100644 (file)
@@ -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 (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 601145ade030de131722e07f9806d4325c6437ad..9ce4fa40d49c6b95dc03a526c33ad506a7a29dfe 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".printf (error_type.to_string ()));
+                               }
                                error_type.check (context);
 
                                // check whether error type is at least as accessible as the delegate
index 42f74a10b3db38658918cb2641c1c3aafae0c1a6..d7aeb33bf80a721ae194854532e2e5944695db71 100644 (file)
@@ -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