[vala/wip/issue/278: 872/872] Add support for sealed classes




commit c283eee2a53ed1969f0d078229e768f969b2446e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jul 27 14:55:22 2021 +0200

    Add support for sealed classes
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/278

 codegen/valaccodebasemodule.vala       |   4 +
 codegen/valaclassregisterfunction.vala |   2 +
 codegen/valagirwriter.vala             |   3 +
 codegen/valagtypemodule.vala           |  28 ++-
 tests/Makefile.am                      |   2 +
 tests/girwriter/class-final.test       |  57 +++++
 tests/parser/sealed-class.c-expected   | 370 +++++++++++++++++++++++++++++++++
 tests/parser/sealed-class.vala         |   8 +
 vala/valaclass.vala                    |   5 -
 vapi/gobject-2.0.vapi                  |   7 +-
 10 files changed, 471 insertions(+), 15 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 43f89e80c..0c79686de 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -693,6 +693,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (sym is Constant && ((Constant) sym).value is InitializerList) {
                        return false;
                }
+               // sealed classes are special
+               if (sym is Class && ((Class) sym).is_sealed) {
+                       return false;
+               }
                if (sym.external_package || in_generated_header
                    || (sym.is_extern && get_ccode_header_filenames (sym).length > 0)) {
                        // add feature test macros
diff --git a/codegen/valaclassregisterfunction.vala b/codegen/valaclassregisterfunction.vala
index 5c9b3cfd4..625ac12a5 100644
--- a/codegen/valaclassregisterfunction.vala
+++ b/codegen/valaclassregisterfunction.vala
@@ -92,6 +92,8 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
        public override string get_type_flags () {
                if (class_reference.is_abstract) {
                        return "G_TYPE_FLAG_ABSTRACT";
+               } else if (CodeContext.get ().require_glib_version (2, 70) && class_reference.is_sealed) {
+                       return "G_TYPE_FLAG_FINAL";
                } else {
                        return "0";
                }
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 49a8112a2..c946cb4e9 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -445,6 +445,9 @@ public class Vala.GIRWriter : CodeVisitor {
                        if (cl.is_abstract) {
                                buffer.append_printf (" abstract=\"1\"");
                        }
+                       if (cl.is_sealed) {
+                               buffer.append_printf (" final=\"1\"");
+                       }
                        write_symbol_attributes (cl);
                        buffer.append_printf (">\n");
                        indent++;
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index a54b32619..3a6e3f4f1 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -75,17 +75,23 @@ public class Vala.GTypeModule : GErrorModule {
                        macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (get_ccode_type_id 
(cl), get_ccode_name (cl));
                        decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf 
(get_ccode_type_cast_function (cl)), macro));
 
-                       macro = "(G_TYPE_CHECK_CLASS_CAST ((klass), %s, %s))".printf (get_ccode_type_id (cl), 
get_ccode_type_name (cl));
-                       decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(klass)".printf 
(get_ccode_class_type_function (cl)), macro));
+                       if (!(cl.is_sealed && decl_space.file_type == CCodeFileType.PUBLIC_HEADER)) {
+                               macro = "(G_TYPE_CHECK_CLASS_CAST ((klass), %s, %s))".printf 
(get_ccode_type_id (cl), get_ccode_type_name (cl));
+                               decl_space.add_type_declaration (new CCodeMacroReplacement 
("%s(klass)".printf (get_ccode_class_type_function (cl)), macro));
+                       }
 
                        macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (get_ccode_type_id (cl));
                        decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf 
(get_ccode_type_check_function (cl)), macro));
 
-                       macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (get_ccode_type_id (cl));
-                       decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(klass)".printf 
(get_ccode_class_type_check_function (cl)), macro));
+                       if (!(cl.is_sealed && decl_space.file_type == CCodeFileType.PUBLIC_HEADER)) {
+                               macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (get_ccode_type_id 
(cl));
+                               decl_space.add_type_declaration (new CCodeMacroReplacement 
("%s(klass)".printf (get_ccode_class_type_check_function (cl)), macro));
+                       }
 
-                       macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %s))".printf (get_ccode_type_id (cl), 
get_ccode_type_name (cl));
-                       decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf 
(get_ccode_type_get_function (cl)), macro));
+                       if (!(cl.is_sealed && decl_space.file_type == CCodeFileType.PUBLIC_HEADER)) {
+                               macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %s))".printf 
(get_ccode_type_id (cl), get_ccode_type_name (cl));
+                               decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf 
(get_ccode_type_get_function (cl)), macro));
+                       }
                        decl_space.add_type_declaration (new CCodeNewline ());
                }
 
@@ -202,7 +208,7 @@ public class Vala.GTypeModule : GErrorModule {
                        }
                }
 
-               if (is_gtypeinstance) {
+               if (is_gtypeinstance && !(cl.is_sealed && decl_space.file_type == 
CCodeFileType.PUBLIC_HEADER)) {
                        decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf 
(get_ccode_type_name (cl)), new CCodeVariableDeclarator (get_ccode_type_name (cl))));
 
                        var type_fun = new ClassRegisterFunction (cl);
@@ -253,6 +259,10 @@ public class Vala.GTypeModule : GErrorModule {
 
                generate_class_declaration (cl, decl_space);
 
+               if (cl.is_sealed && decl_space.file_type == CCodeFileType.PUBLIC_HEADER) {
+                       return;
+               }
+
                bool is_gtypeinstance = !cl.is_compact;
                bool is_fundamental = is_gtypeinstance && cl.base_class == null;
 
@@ -656,14 +666,14 @@ public class Vala.GTypeModule : GErrorModule {
                        cfile.add_type_declaration (prop_array_decl);
                }
 
-               if (!cl.is_internal_symbol ()) {
+               if (!cl.is_internal_symbol () || cl.is_sealed) {
                        if (!cl.is_opaque) {
                                generate_class_struct_declaration (cl, header_file);
                        } else {
                                generate_class_declaration (cl, header_file);
                        }
                }
-               if (!cl.is_private_symbol ()) {
+               if (!cl.is_private_symbol () || cl.is_sealed) {
                        generate_class_struct_declaration (cl, internal_header_file);
                }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cc26ede8b..fd840eb30 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -772,6 +772,7 @@ TESTS = \
        gir/symbol-type-csuffix.test \
        gir/union.test \
        gir/union-transparent.test \
+       girwriter/class-final.test \
        girwriter/combined.test \
        gtktemplate/gtkcallback-incompatible.test \
        gtktemplate/gtkcallback-unknown.test \
@@ -891,6 +892,7 @@ TESTS = \
        parser/property-set-redefined.test \
        parser/qualified-member-access.vala \
        parser/qualified-symbol-access.vala \
+       parser/sealed-class.vala \
        parser/signal-no-class.test \
        parser/signal-no-static.test \
        parser/statement-keyword-as-identifier.vala \
diff --git a/tests/girwriter/class-final.test b/tests/girwriter/class-final.test
new file mode 100644
index 000000000..00b50022d
--- /dev/null
+++ b/tests/girwriter/class-final.test
@@ -0,0 +1,57 @@
+GIRWriter
+
+Input:
+
+public class Test.Foo {
+}
+public sealed class Test.Bar : Test.Foo {
+}
+
+Output:
+
+<include name="GObject" version="2.0"/>
+<package name="test"/>
+<c:include name="test.h"/>
+<namespace name="Test" version="1.2" c:prefix="Test" c:identifier-prefixes="Test" c:symbol-prefixes="test">
+  <class name="TestFoo" c:type="TestTestFoo" c:symbol-prefix="foo" glib:type-name="TestTestFoo" 
glib:get-type="test_test_foo_get_type" glib:type-struct="TestFooClass" glib:fundamental="1" 
glib:ref-func="test_test_foo_ref" glib:unref-func="test_test_foo_unref" 
glib:set-value-func="test_test_value_set_foo" glib:get-value-func="test_test_value_get_foo">
+    <field name="parent_instance" readable="0" private="1">
+      <type name="GObject.TypeInstance" c:type="GTypeInstance"/>
+    </field>
+    <field name="ref_count">
+      <type name="gint" c:type="volatile int"/>
+    </field>
+    <field name="priv" readable="0" private="1">
+      <type name="TestFooPrivate" c:type="TestTestFooPrivate*"/>
+    </field>
+    <constructor name="new" c:identifier="test_test_foo_new">
+      <return-value transfer-ownership="full">
+        <type name="Test.Foo" c:type="TestTestFoo*"/>
+      </return-value>
+    </constructor>
+  </class>
+  <record name="TestFooClass" c:type="TestTestFooClass" glib:is-gtype-struct-for="TestFoo">
+    <field name="parent_class" readable="0" private="1">
+      <type name="GObject.TypeClass" c:type="GTypeClass"/>
+    </field>
+  </record>
+  <record name="TestFooPrivate" c:type="TestTestFooPrivate" disguised="1"/>
+  <class name="TestBar" c:type="TestTestBar" c:symbol-prefix="bar" glib:type-name="TestTestBar" 
glib:get-type="test_test_bar_get_type" glib:type-struct="TestBarClass" parent="Test.Foo" final="1">
+    <field name="parent_instance" readable="0" private="1">
+      <type name="Test.Foo" c:type="TestTestFoo"/>
+    </field>
+    <field name="priv" readable="0" private="1">
+      <type name="TestBarPrivate" c:type="TestTestBarPrivate*"/>
+    </field>
+    <constructor name="new" c:identifier="test_test_bar_new">
+      <return-value transfer-ownership="full">
+        <type name="Test.Bar" c:type="TestTestBar*"/>
+      </return-value>
+    </constructor>
+  </class>
+  <record name="TestBarClass" c:type="TestTestBarClass" glib:is-gtype-struct-for="TestBar">
+    <field name="parent_class" readable="0" private="1">
+      <type name="Test.FooClass" c:type="TestTestFooClass"/>
+    </field>
+  </record>
+  <record name="TestBarPrivate" c:type="TestTestBarPrivate" disguised="1"/>
+</namespace>
diff --git a/tests/parser/sealed-class.c-expected b/tests/parser/sealed-class.c-expected
new file mode 100644
index 000000000..8c9afc5a9
--- /dev/null
+++ b/tests/parser/sealed-class.c-expected
@@ -0,0 +1,370 @@
+/* parser_sealed_class.c generated by valac, the Vala compiler
+ * generated from parser_sealed_class.vala, do not modify */
+
+#include <glib-object.h>
+#include <gobject/gvaluecollector.h>
+
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+#define TYPE_FOO (foo_get_type ())
+#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
+#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
+#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO))
+#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO))
+#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass))
+
+typedef struct _Foo Foo;
+typedef struct _FooClass FooClass;
+typedef struct _FooPrivate FooPrivate;
+typedef struct _ParamSpecFoo ParamSpecFoo;
+
+#define TYPE_BAR (bar_get_type ())
+#define BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR, Bar))
+#define BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BAR, BarClass))
+#define IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BAR))
+#define IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BAR))
+#define BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BAR, BarClass))
+
+typedef struct _Bar Bar;
+typedef struct _BarClass BarClass;
+typedef struct _BarPrivate BarPrivate;
+enum  {
+       BAR_0_PROPERTY,
+       BAR_NUM_PROPERTIES
+};
+static GParamSpec* bar_properties[BAR_NUM_PROPERTIES];
+
+struct _Foo {
+       GTypeInstance parent_instance;
+       volatile int ref_count;
+       FooPrivate * priv;
+};
+
+struct _FooClass {
+       GTypeClass parent_class;
+       void (*finalize) (Foo *self);
+};
+
+struct _ParamSpecFoo {
+       GParamSpec parent_instance;
+};
+
+struct _Bar {
+       GObject parent_instance;
+       BarPrivate * priv;
+};
+
+struct _BarClass {
+       GObjectClass parent_class;
+};
+
+static gpointer foo_parent_class = NULL;
+static gpointer bar_parent_class = NULL;
+
+VALA_EXTERN gpointer foo_ref (gpointer instance);
+VALA_EXTERN void foo_unref (gpointer instance);
+VALA_EXTERN GParamSpec* param_spec_foo (const gchar* name,
+                            const gchar* nick,
+                            const gchar* blurb,
+                            GType object_type,
+                            GParamFlags flags);
+VALA_EXTERN void value_set_foo (GValue* value,
+                    gpointer v_object);
+VALA_EXTERN void value_take_foo (GValue* value,
+                     gpointer v_object);
+VALA_EXTERN gpointer value_get_foo (const GValue* value);
+VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, foo_unref)
+VALA_EXTERN Foo* foo_new (void);
+VALA_EXTERN Foo* foo_construct (GType object_type);
+static void foo_finalize (Foo * obj);
+static GType foo_get_type_once (void);
+VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Bar, g_object_unref)
+VALA_EXTERN Bar* bar_new (void);
+VALA_EXTERN Bar* bar_construct (GType object_type);
+static GType bar_get_type_once (void);
+static void _vala_main (void);
+
+Foo*
+foo_construct (GType object_type)
+{
+       Foo* self = NULL;
+       self = (Foo*) g_type_create_instance (object_type);
+       return self;
+}
+
+Foo*
+foo_new (void)
+{
+       return foo_construct (TYPE_FOO);
+}
+
+static void
+value_foo_init (GValue* value)
+{
+       value->data[0].v_pointer = NULL;
+}
+
+static void
+value_foo_free_value (GValue* value)
+{
+       if (value->data[0].v_pointer) {
+               foo_unref (value->data[0].v_pointer);
+       }
+}
+
+static void
+value_foo_copy_value (const GValue* src_value,
+                      GValue* dest_value)
+{
+       if (src_value->data[0].v_pointer) {
+               dest_value->data[0].v_pointer = foo_ref (src_value->data[0].v_pointer);
+       } else {
+               dest_value->data[0].v_pointer = NULL;
+       }
+}
+
+static gpointer
+value_foo_peek_pointer (const GValue* value)
+{
+       return value->data[0].v_pointer;
+}
+
+static gchar*
+value_foo_collect_value (GValue* value,
+                         guint n_collect_values,
+                         GTypeCValue* collect_values,
+                         guint collect_flags)
+{
+       if (collect_values[0].v_pointer) {
+               Foo * object;
+               object = collect_values[0].v_pointer;
+               if (object->parent_instance.g_class == NULL) {
+                       return g_strconcat ("invalid unclassed object pointer for value type `", 
G_VALUE_TYPE_NAME (value), "'", NULL);
+               } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
+                       return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE 
(object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
+               }
+               value->data[0].v_pointer = foo_ref (object);
+       } else {
+               value->data[0].v_pointer = NULL;
+       }
+       return NULL;
+}
+
+static gchar*
+value_foo_lcopy_value (const GValue* value,
+                       guint n_collect_values,
+                       GTypeCValue* collect_values,
+                       guint collect_flags)
+{
+       Foo ** object_p;
+       object_p = collect_values[0].v_pointer;
+       if (!object_p) {
+               return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+       }
+       if (!value->data[0].v_pointer) {
+               *object_p = NULL;
+       } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
+               *object_p = value->data[0].v_pointer;
+       } else {
+               *object_p = foo_ref (value->data[0].v_pointer);
+       }
+       return NULL;
+}
+
+GParamSpec*
+param_spec_foo (const gchar* name,
+                const gchar* nick,
+                const gchar* blurb,
+                GType object_type,
+                GParamFlags flags)
+{
+       ParamSpecFoo* spec;
+       g_return_val_if_fail (g_type_is_a (object_type, TYPE_FOO), NULL);
+       spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
+       G_PARAM_SPEC (spec)->value_type = object_type;
+       return G_PARAM_SPEC (spec);
+}
+
+gpointer
+value_get_foo (const GValue* value)
+{
+       g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO), NULL);
+       return value->data[0].v_pointer;
+}
+
+void
+value_set_foo (GValue* value,
+               gpointer v_object)
+{
+       Foo * old;
+       g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO));
+       old = value->data[0].v_pointer;
+       if (v_object) {
+               g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOO));
+               g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE 
(value)));
+               value->data[0].v_pointer = v_object;
+               foo_ref (value->data[0].v_pointer);
+       } else {
+               value->data[0].v_pointer = NULL;
+       }
+       if (old) {
+               foo_unref (old);
+       }
+}
+
+void
+value_take_foo (GValue* value,
+                gpointer v_object)
+{
+       Foo * old;
+       g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO));
+       old = value->data[0].v_pointer;
+       if (v_object) {
+               g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOO));
+               g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE 
(value)));
+               value->data[0].v_pointer = v_object;
+       } else {
+               value->data[0].v_pointer = NULL;
+       }
+       if (old) {
+               foo_unref (old);
+       }
+}
+
+static void
+foo_class_init (FooClass * klass,
+                gpointer klass_data)
+{
+       foo_parent_class = g_type_class_peek_parent (klass);
+       ((FooClass *) klass)->finalize = foo_finalize;
+}
+
+static void
+foo_instance_init (Foo * self,
+                   gpointer klass)
+{
+       self->ref_count = 1;
+}
+
+static void
+foo_finalize (Foo * obj)
+{
+       Foo * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOO, Foo);
+       g_signal_handlers_destroy (self);
+}
+
+static GType
+foo_get_type_once (void)
+{
+       static const GTypeValueTable g_define_type_value_table = { value_foo_init, value_foo_free_value, 
value_foo_copy_value, value_foo_peek_pointer, "p", value_foo_collect_value, "p", value_foo_lcopy_value };
+       static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, 
(GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, 
(GInstanceInitFunc) foo_instance_init, &g_define_type_value_table };
+       static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | 
G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
+       GType foo_type_id;
+       foo_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Foo", &g_define_type_info, 
&g_define_type_fundamental_info, 0);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__volatile = 0;
+       if (g_once_init_enter (&foo_type_id__volatile)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__volatile, foo_type_id);
+       }
+       return foo_type_id__volatile;
+}
+
+gpointer
+foo_ref (gpointer instance)
+{
+       Foo * self;
+       self = instance;
+       g_atomic_int_inc (&self->ref_count);
+       return instance;
+}
+
+void
+foo_unref (gpointer instance)
+{
+       Foo * self;
+       self = instance;
+       if (g_atomic_int_dec_and_test (&self->ref_count)) {
+               FOO_GET_CLASS (self)->finalize (self);
+               g_type_free_instance ((GTypeInstance *) self);
+       }
+}
+
+Bar*
+bar_construct (GType object_type)
+{
+       Bar * self = NULL;
+       self = (Bar*) g_object_new (object_type, NULL);
+       return self;
+}
+
+Bar*
+bar_new (void)
+{
+       return bar_construct (TYPE_BAR);
+}
+
+static void
+bar_class_init (BarClass * klass,
+                gpointer klass_data)
+{
+       bar_parent_class = g_type_class_peek_parent (klass);
+}
+
+static void
+bar_instance_init (Bar * self,
+                   gpointer klass)
+{
+}
+
+static GType
+bar_get_type_once (void)
+{
+       static const GTypeInfo g_define_type_info = { sizeof (BarClass), (GBaseInitFunc) NULL, 
(GBaseFinalizeFunc) NULL, (GClassInitFunc) bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Bar), 0, 
(GInstanceInitFunc) bar_instance_init, NULL };
+       GType bar_type_id;
+       bar_type_id = g_type_register_static (G_TYPE_OBJECT, "Bar", &g_define_type_info, 0);
+       return bar_type_id;
+}
+
+GType
+bar_get_type (void)
+{
+       static volatile gsize bar_type_id__volatile = 0;
+       if (g_once_init_enter (&bar_type_id__volatile)) {
+               GType bar_type_id;
+               bar_type_id = bar_get_type_once ();
+               g_once_init_leave (&bar_type_id__volatile, bar_type_id);
+       }
+       return bar_type_id__volatile;
+}
+
+static void
+_vala_main (void)
+{
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/parser/sealed-class.vala b/tests/parser/sealed-class.vala
new file mode 100644
index 000000000..b6f420703
--- /dev/null
+++ b/tests/parser/sealed-class.vala
@@ -0,0 +1,8 @@
+sealed class Foo {
+}
+
+sealed class Bar : Object {
+}
+
+void main () {
+}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index b6bd63773..ee4ed624f 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -606,11 +606,6 @@ public class Vala.Class : ObjectTypeSymbol {
                                Report.error (source_reference, "Sealed class `%s' cannot be abstract", 
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 */
diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi
index 53f63af1e..34495100c 100644
--- a/vapi/gobject-2.0.vapi
+++ b/vapi/gobject-2.0.vapi
@@ -684,6 +684,9 @@ namespace GLib {
                public bool is_derived ();
                [CCode (cname = "G_TYPE_IS_ENUM")]
                public bool is_enum ();
+               [CCode (cname = "G_TYPE_IS_FINAL")]
+               [Version (since = "2.70")]
+               public bool is_final ();
                [CCode (cname = "G_TYPE_IS_FLAGS")]
                public bool is_flags ();
                [CCode (cname = "G_TYPE_IS_FUNDAMENTAL")]
@@ -900,7 +903,9 @@ namespace GLib {
        [Flags]
        public enum TypeFlags {
                ABSTRACT,
-               VALUE_ABSTRACT
+               VALUE_ABSTRACT,
+               [Version (since = "2.70")]
+               FINAL
        }
        [CCode (cheader_filename = "glib-object.h", cprefix = "G_TYPE_FLAG_", has_type_id = false)]
        [Flags]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]