[vala/staging] vala: Add accessibility check of type for constants and structs base type
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Add accessibility check of type for constants and structs base type
- Date: Sat, 6 Nov 2021 17:56:13 +0000 (UTC)
commit 995060a7dc3789c0b5f48443fb4a5695e20dd2e8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Nov 6 18:55:37 2021 +0100
vala: Add accessibility check of type for constants and structs base type
tests/Makefile.am | 2 ++
tests/semantic/constant-type-less-accessible.test | 10 ++++++++++
tests/semantic/struct-base-type-less-accessible.test | 11 +++++++++++
vala/valaconstant.vala | 7 +++++++
vala/valastruct.vala | 7 +++++++
5 files changed, 37 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3f4971e7a..eadf61b84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..16f51ec60
--- /dev/null
+++ b/tests/semantic/constant-type-less-accessible.test
@@ -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
index 000000000..0989d5464
--- /dev/null
+++ b/tests/semantic/struct-base-type-less-accessible.test
@@ -0,0 +1,11 @@
+Invalid Code
+
+struct Bar {
+ public int i;
+}
+
+public struct Foo : Bar {
+}
+
+void main () {
+}
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index fcbb4c321..8b5f9ea88 100644
--- a/vala/valaconstant.vala
+++ b/vala/valaconstant.vala
@@ -121,6 +121,13 @@ 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 ());
+ return false;
+ }
+
if (!external) {
if (value == null) {
// constants from fast-vapi files are special
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 4c4e28fdc..c7e6d335c 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -510,6 +510,13 @@ 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 ());
+ return false;
+ }
}
foreach (TypeParameter p in type_parameters) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]