]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add accessibility check of type for constants and structs base type
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 6 Nov 2021 17:55:37 +0000 (18:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 6 Nov 2021 18:34:28 +0000 (19:34 +0100)
tests/Makefile.am
tests/semantic/constant-type-less-accessible.test [new file with mode: 0644]
tests/semantic/struct-base-type-less-accessible.test [new file with mode: 0644]
vala/valaconstant.vala
vala/valastruct.vala

index 3f4971e7a224c2c75b6b001459c35f71d67ae8cf..eadf61b848e605d03b16846a9de4da81b964a016 100644 (file)
@@ -1012,6 +1012,7 @@ TESTS = \
        semantic/constant-pointer.test \
        semantic/constant-reassignment-element.test \
        semantic/constant-reassignment-member.test \
+       semantic/constant-type-less-accessible.test \
        semantic/constant-value.test \
        semantic/constant-value-missing.test \
        semantic/constant-value-type.test \
@@ -1173,6 +1174,7 @@ TESTS = \
        semantic/signal-disconnect-empty-invalid.test \
        semantic/signal-disconnect-invalid.test \
        semantic/signal-return-valist.test \
+       semantic/struct-base-type-less-accessible.test \
        semantic/struct-field-initializer.test \
        semantic/struct-invalid-base.test \
        semantic/struct-recursive.test \
diff --git a/tests/semantic/constant-type-less-accessible.test b/tests/semantic/constant-type-less-accessible.test
new file mode 100644 (file)
index 0000000..16f51ec
--- /dev/null
@@ -0,0 +1,10 @@
+Invalid Code
+
+struct Bar {
+       public int i;
+}
+
+public const Bar FOO = { 42 };
+
+void main () {
+}
diff --git a/tests/semantic/struct-base-type-less-accessible.test b/tests/semantic/struct-base-type-less-accessible.test
new file mode 100644 (file)
index 0000000..0989d54
--- /dev/null
@@ -0,0 +1,11 @@
+Invalid Code
+
+struct Bar {
+       public int i;
+}
+
+public struct Foo : Bar {
+}
+
+void main () {
+}
index fcbb4c321dc777842e0ff6b08d8cc780d4af55d5..5b30e7f38374223f5d4479e711fad3d0e5af47dc 100644 (file)
@@ -121,6 +121,12 @@ public class Vala.Constant : Symbol {
                        return false;
                }
 
+               // check whether constant type is at least as accessible as the constant
+               if (!context.analyzer.is_type_accessible (this, type_reference)) {
+                       error = true;
+                       Report.error (source_reference, "constant type `%s' is less accessible than constant `%s'", type_reference.to_string (), get_full_name ());
+               }
+
                if (!external) {
                        if (value == null) {
                                // constants from fast-vapi files are special
index 4c4e28fdc7370131f564d555e784e03762034ce2..2ac7034af41835080dbb0b754cb7fd0972da9b03 100644 (file)
@@ -510,6 +510,12 @@ public class Vala.Struct : TypeSymbol {
                                Report.error (source_reference, "The base type `%s' of struct `%s' is not a struct", base_type.to_string (), get_full_name ());
                                return false;
                        }
+
+                       // check whether base type is at least as accessible as the struct
+                       if (!context.analyzer.is_type_accessible (this, base_type)) {
+                               error = true;
+                               Report.error (source_reference, "base type `%s' is less accessible than struct `%s'", base_type.to_string (), get_full_name ());
+                       }
                }
 
                foreach (TypeParameter p in type_parameters) {