From: Rico Tzschichholz Date: Sat, 23 Oct 2021 13:27:12 +0000 (+0200) Subject: vala: Report error for non ErrorType in throws X-Git-Tag: 0.55.1~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d622c776898fb250c02566762d70b466246833f4;p=thirdparty%2Fvala.git vala: Report error for non ErrorType in throws --- 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 2926a7ab7..dc41e3d77 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