]> 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>
Wed, 22 Jul 2020 13:11:41 +0000 (15:11 +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 4f5fd64dcb894eca7eb67895848b1543cd008f56..b224eb437943570536281fa47f4188510bdeb4a4 100644 (file)
@@ -823,6 +823,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 23d40fd393e33327c0fb191d80482b336a7064a3..ed15bf46d95ebe1a2888caca3237c897f7774ae4 100644 (file)
@@ -120,6 +120,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 abe9f86348cafd0fac9b5e355c6f845eb4794471..d4576be685f668604256c4290cf617fccf2b7c95 100644 (file)
@@ -326,6 +326,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;
+                               }
                        }
                }