]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Check error-type accessibility of creation methods and delegates
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 22 Jul 2020 13:04:04 +0000 (15:04 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 26 Jul 2020 08:55:35 +0000 (10:55 +0200)
tests/Makefile.am
tests/semantic/creation-error-accessibility.test [new file with mode: 0644]
tests/semantic/delegate-error-accessibility.test [new file with mode: 0644]
vala/valacreationmethod.vala
vala/valadelegate.vala

index 1fae4c1bd8bb53ac3c0f40b5269e91475c892116..c79ea9f2229890c00abf1e8f36789f92d5ae4cf4 100644 (file)
@@ -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 (file)
index 0000000..3fde91c
--- /dev/null
@@ -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 (file)
index 0000000..1bc741e
--- /dev/null
@@ -0,0 +1,10 @@
+Invalid Code
+
+errordomain FooError {
+       BAR
+}
+
+public delegate void Foo () throws FooError;
+
+void main () {
+}
index 710d8e5cc9051a2b55715204fea9f3527a97bb8b..d1b65c64a35cbab023352154d77922c2c53ee22b 100644 (file)
@@ -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;
+                               }
                        }
                }
 
index ae9a563450dbf7c3bd508a9174b00b7d5f9453ed..d2e9c4ef0cb390eca4e76699306e62f4a8c1f3b2 100644 (file)
@@ -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;
+                               }
                        }
                }