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



commit e164640813fba66c71bee2bd566aa67bf7a4f6de
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 de919b23b..393c0ee01 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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 9b590ca47..249adcdfc 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -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
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 2e393bd38..7a2c17026 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]