From: Rico Tzschichholz Date: Wed, 22 Jul 2020 13:04:04 +0000 (+0200) Subject: vala: Check error-type accessibility of creation methods and delegates X-Git-Tag: 0.40.24~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb7653642be12a0b98ca04c2c4d544af8855a3bd;p=thirdparty%2Fvala.git vala: Check error-type accessibility of creation methods and delegates --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 18a8ccfde..bacb16fa4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -704,6 +704,8 @@ TESTS = \ semantic/constant-value-type.test \ semantic/constant-void.test \ semantic/construct-without-gobject.test \ + semantic/creation-error-accessibility.test \ + semantic/delegate-error-accessibility.test \ semantic/delegate-return-valist.test \ semantic/delegate-too-few-type-arguments.test \ semantic/delegate-too-many-type-arguments.test \ diff --git a/tests/semantic/creation-error-accessibility.test b/tests/semantic/creation-error-accessibility.test new file mode 100644 index 000000000..3fde91c16 --- /dev/null +++ b/tests/semantic/creation-error-accessibility.test @@ -0,0 +1,13 @@ +Invalid Code + +errordomain FooError { + BAR +} + +public class Foo { + public Foo () throws FooError { + } +} + +void main () { +} diff --git a/tests/semantic/delegate-error-accessibility.test b/tests/semantic/delegate-error-accessibility.test new file mode 100644 index 000000000..1bc741eee --- /dev/null +++ b/tests/semantic/delegate-error-accessibility.test @@ -0,0 +1,10 @@ +Invalid Code + +errordomain FooError { + BAR +} + +public delegate void Foo () throws FooError; + +void main () { +} diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index 114bbf8c3..e917529e4 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -113,6 +113,13 @@ public class Vala.CreationMethod : Method { foreach (DataType error_type in get_error_types ()) { error_type.check (context); + + // check whether error type is at least as accessible as the creation method + if (!context.analyzer.is_type_accessible (this, error_type)) { + error = true; + Report.error (source_reference, "error type `%s' is less accessible than creation method `%s'".printf (error_type.to_string (), get_full_name ())); + return false; + } } foreach (Expression precondition in get_preconditions ()) { diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala index cd9911d1d..9c68fd204 100644 --- a/vala/valadelegate.vala +++ b/vala/valadelegate.vala @@ -282,6 +282,13 @@ public class Vala.Delegate : TypeSymbol, Callable { foreach (DataType error_type in get_error_types ()) { error_type.check (context); + + // check whether error type is at least as accessible as the delegate + if (!context.analyzer.is_type_accessible (this, error_type)) { + error = true; + Report.error (source_reference, "error type `%s' is less accessible than delegate `%s'".printf (error_type.to_string (), get_full_name ())); + return false; + } } context.analyzer.current_source_file = old_source_file;