[vala/0.46] vala: Check error-type accessibility of creation methods and delegates



commit 10d93c6349478d52c91f40b05d0bdb01e4b72e5f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Jul 22 15:04:04 2020 +0200

    vala: Check error-type accessibility of creation methods and delegates

 tests/Makefile.am                                |  2 ++
 tests/semantic/creation-error-accessibility.test | 13 +++++++++++++
 tests/semantic/delegate-error-accessibility.test | 10 ++++++++++
 vala/valacreationmethod.vala                     |  7 +++++++
 vala/valadelegate.vala                           |  7 +++++++
 5 files changed, 39 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1fae4c1bd..c79ea9f22 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -779,6 +779,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 710d8e5cc..d1b65c64a 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -116,6 +116,13 @@ public class Vala.CreationMethod : Method {
                if (error_types != null) {
                        foreach (DataType error_type in 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;
+                               }
                        }
                }
 
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index ae9a56345..d2e9c4ef0 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -320,6 +320,13 @@ public class Vala.Delegate : TypeSymbol, Callable {
                if (error_types != null) {
                        foreach (DataType error_type in 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;
+                               }
                        }
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]