]> 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 10:34:24 +0000 (12:34 +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 18a8ccfde823de039ce806132ec9a3195574d6f8..bacb16fa43f3167dd1dc9ea8b01496097f12c3c6 100644 (file)
@@ -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 (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 114bbf8c36e0870bf07ecae07bec98132ec19a1d..e917529e4f96cc169ec8f3a66fbc6f144bbede1a 100644 (file)
@@ -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 ()) {
index cd9911d1de3419b14eb7cda9bb6e0a4c93d5346f..9c68fd2049b0b723b1c8cef766d572f2a7fdc7db 100644 (file)
@@ -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;