summaryrefslogtreecommitdiff
path: root/vala/valaclass.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-06-16 19:28:24 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2020-02-19 13:29:33 +0100
commitc16b665cb90c66c5ed8362fa70989bde1eaee272 (patch)
tree6728eb7f02af42ac98166f5f0961aff4ee30eb07 /vala/valaclass.vala
parentc24a807efe5f06e04d6839a48521730d20769045 (diff)
downloadvala-c16b665cb90c66c5ed8362fa70989bde1eaee272.tar.gz
Add support for sealed classes in bindings
The "sealed" keyword was available and parsed for a long time. So simply pick it up information and expose it in the AST. Issue an error when it is used in vala source. See https://gitlab.gnome.org/GNOME/vala/issues/278
Diffstat (limited to 'vala/valaclass.vala')
-rw-r--r--vala/valaclass.vala29
1 files changed, 29 insertions, 0 deletions
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index e9312c415..c4f196c64 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -38,6 +38,12 @@ public class Vala.Class : ObjectTypeSymbol {
public bool is_abstract { get; set; }
/**
+ * Specifies whether this class is sealed. Sealed classes may not be
+ * sub-classed.
+ */
+ public bool is_sealed { get; set; }
+
+ /**
* Instances of compact classes are fast to create and have a
* compact memory layout. Compact classes don't support runtime
* type information or virtual methods.
@@ -582,6 +588,29 @@ public class Vala.Class : ObjectTypeSymbol {
add_constructor (c);
}
+ if (base_class != null && base_class.is_sealed) {
+ error = true;
+ Report.error (source_reference, "`%s' cannot inherit from sealed class `%s'".printf (get_full_name (), base_class.get_full_name ()));
+ }
+
+ if (is_sealed) {
+ if (is_compact) {
+ error = true;
+ Report.error (source_reference, "Sealed class `%s' cannot be compact".printf (get_full_name ()));
+ return false;
+ }
+ if (is_abstract) {
+ error = true;
+ Report.error (source_reference, "Sealed class `%s' cannot be abstract".printf (get_full_name ()));
+ return false;
+ }
+ if (!external_package) {
+ error = true;
+ Report.error (source_reference, "Sealed classes are not fully supported yet");
+ return false;
+ }
+ }
+
/* process enums first to avoid order problems in C code */
foreach (Enum en in get_enums ()) {
en.check (context);