this.is_fundamental = data.is_fundamental ();
this.is_abstract = data.is_abstract;
+ this.is_sealed = data.is_sealed;
}
string? _get_private_cname (Vala.Class element) {
get;
}
+ /**
+ * Specifies whether this class is sealed. Sealed classes may not be
+ * sub-classed.
+ */
+ public bool is_sealed {
+ private set;
+ get;
+ }
+
/**
* Specifies whether this class is fundamental.
*/
if (is_abstract) {
signature.append_keyword ("abstract");
}
+ if (is_sealed) {
+ signature.append_keyword ("sealed");
+ }
signature.append_keyword ("class");
signature.append_symbol (this);
objects/property-simple-type-struct-nullable.vala \
objects/property-static.vala \
objects/regex.vala \
+ objects/sealed-abstract-class.test \
+ objects/sealed-class.test \
+ objects/sealed-compact-class.test \
objects/signals.vala \
objects/signals-enum-marshal.vala \
objects/signals-delegate.vala \
--- /dev/null
+Invalid Code
+
+sealed abstract class Foo {
+}
+
+void main () {
+}
--- /dev/null
+Invalid Code
+
+sealed class Foo {
+}
+
+class Bar : Foo {
+}
+
+void main () {
+}
--- /dev/null
+Invalid Code
+
+[Compact]
+sealed class Foo {
+}
+
+void main () {
+}
*/
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
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);
if (cl.is_abstract) {
write_string ("abstract ");
}
+ if (cl.is_sealed) {
+ write_string ("sealed ");
+ }
write_string ("class ");
write_identifier (cl.name);
VFUNC_NAME,
VIRTUAL,
ABSTRACT,
+ SEALED,
SCOPE,
STRUCT,
THROWS,
if (current.new_symbol) {
cl = new Class (current.name, current.source_reference);
cl.is_abstract = metadata.get_bool (ArgumentType.ABSTRACT, reader.get_attribute ("abstract") == "1");
+ cl.is_sealed = metadata.get_bool (ArgumentType.SEALED, false);
if (parent != null) {
cl.add_base_type (parse_type_from_gir_name (parent));
if (ModifierFlags.ABSTRACT in flags) {
cl.is_abstract = true;
}
+ if (ModifierFlags.SEALED in flags) {
+ cl.is_sealed = true;
+ }
if (ModifierFlags.EXTERN in flags) {
cl.is_extern = true;
}