]> 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>
Sat, 23 Oct 2021 13:27:12 +0000 (15:27 +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 de919b23bd087ef99f81b05684d7464854e41407..393c0ee019afa2950ec5062c8bca7077e0e3b740 100644 (file)
@@ -635,6 +635,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 \
@@ -643,6 +644,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 9b590ca47d5c3870b4d83cf909a9345ba0a91ac0..249adcdfc35eaf63ece3af9323134f8d3a78fc22 100644 (file)
@@ -334,6 +334,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 2926a7ab7278c9ac1e4318bc09f65ed19cad1944..dc41e3d77eac01edd5efcf2f59150845717e39fc 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