[vala/0.54] vala: Non nullable enum types are simple types



commit f9098a27fbf5639a2d2bb3d0f7358bda3c35173c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Dec 16 15:31:47 2021 +0100

    vala: Non nullable enum types are simple types
    
    Fixes a regression of 5b6345a6386b05aaf3f11cb3572940413eb878a8
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1268

 tests/Makefile.am                             |   2 +
 tests/constants/member-access-enum.c-expected | 373 ++++++++++++++++++++++++++
 tests/constants/member-access-enum.vala       |  27 ++
 tests/enums/bug666035.c-expected              |   8 +-
 tests/enums/enum-boxed.c-expected             | 246 +++++++++++++++++
 tests/enums/enum-boxed.vala                   |  39 +++
 tests/objects/paramspec.c-expected            |  16 +-
 tests/objects/property-enum.c-expected        |  32 +--
 vala/valadatatype.vala                        |   3 +
 9 files changed, 704 insertions(+), 42 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4ca5c8f57..928c0aa08 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -104,6 +104,7 @@ TESTS = \
        constants/array-type-invalid.test \
        constants/glog.vala \
        constants/member-access.vala \
+       constants/member-access-enum.vala \
        constants/strings.vala \
        namespace/unique.vala \
        arrays/cast-silent-invalid.test \
@@ -334,6 +335,7 @@ TESTS = \
        control-semantic/variadic-argument-invalid.test \
        enums/default-gtype.vala \
        enums/enum_only.vala \
+       enums/enum-boxed.vala \
        enums/enum-no-gtype.vala \
        enums/enum-gtype-too-short.test \
        enums/enums.vala \
diff --git a/tests/constants/member-access-enum.c-expected b/tests/constants/member-access-enum.c-expected
new file mode 100644
index 000000000..eb2faa69e
--- /dev/null
+++ b/tests/constants/member-access-enum.c-expected
@@ -0,0 +1,373 @@
+/* constants_member_access_enum.c generated by valac, the Vala compiler
+ * generated from constants_member_access_enum.vala, do not modify */
+
+#include <glib-object.h>
+#include <gobject/gvaluecollector.h>
+#include <glib.h>
+
+#define FOO FOO_MANAM
+#define FAZ FOO_MINIM
+#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
+
+typedef enum  {
+       FOO_MANAM = 23,
+       FOO_MINIM = 42
+} Foo;
+
+#define TYPE_FOO (foo_get_type ())
+
+#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;
+typedef struct _ParamSpecBar ParamSpecBar;
+#define _bar_unref0(var) ((var == NULL) ? NULL : (var = (bar_unref (var), NULL)))
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning 
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+
+struct _Bar {
+       GTypeInstance parent_instance;
+       volatile int ref_count;
+       BarPrivate * priv;
+       Foo* foo;
+};
+
+struct _BarClass {
+       GTypeClass parent_class;
+       void (*finalize) (Bar *self);
+};
+
+struct _ParamSpecBar {
+       GParamSpec parent_instance;
+};
+
+static gpointer bar_parent_class = NULL;
+
+VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
+VALA_EXTERN gpointer bar_ref (gpointer instance);
+VALA_EXTERN void bar_unref (gpointer instance);
+VALA_EXTERN GParamSpec* param_spec_bar (const gchar* name,
+                            const gchar* nick,
+                            const gchar* blurb,
+                            GType object_type,
+                            GParamFlags flags);
+VALA_EXTERN void value_set_bar (GValue* value,
+                    gpointer v_object);
+VALA_EXTERN void value_take_bar (GValue* value,
+                     gpointer v_object);
+VALA_EXTERN gpointer value_get_bar (const GValue* value);
+VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Bar, bar_unref)
+VALA_EXTERN Bar* bar_new (Foo _foo);
+VALA_EXTERN Bar* bar_construct (GType object_type,
+                    Foo _foo);
+static void bar_finalize (Bar * obj);
+static GType bar_get_type_once (void);
+static void _vala_main (void);
+static gboolean _foo_equal (const Foo * s1,
+                     const Foo * s2);
+
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_MANAM, "FOO_MANAM", "manam"}, {FOO_MINIM, "FOO_MINIM", 
"minim"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       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;
+}
+
+Bar*
+bar_construct (GType object_type,
+               Foo _foo)
+{
+       Bar* self = NULL;
+       self = (Bar*) g_type_create_instance (object_type);
+       self->foo = &_foo;
+       return self;
+}
+
+Bar*
+bar_new (Foo _foo)
+{
+       return bar_construct (TYPE_BAR, _foo);
+}
+
+static void
+value_bar_init (GValue* value)
+{
+       value->data[0].v_pointer = NULL;
+}
+
+static void
+value_bar_free_value (GValue* value)
+{
+       if (value->data[0].v_pointer) {
+               bar_unref (value->data[0].v_pointer);
+       }
+}
+
+static void
+value_bar_copy_value (const GValue* src_value,
+                      GValue* dest_value)
+{
+       if (src_value->data[0].v_pointer) {
+               dest_value->data[0].v_pointer = bar_ref (src_value->data[0].v_pointer);
+       } else {
+               dest_value->data[0].v_pointer = NULL;
+       }
+}
+
+static gpointer
+value_bar_peek_pointer (const GValue* value)
+{
+       return value->data[0].v_pointer;
+}
+
+static gchar*
+value_bar_collect_value (GValue* value,
+                         guint n_collect_values,
+                         GTypeCValue* collect_values,
+                         guint collect_flags)
+{
+       if (collect_values[0].v_pointer) {
+               Bar * 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 = bar_ref (object);
+       } else {
+               value->data[0].v_pointer = NULL;
+       }
+       return NULL;
+}
+
+static gchar*
+value_bar_lcopy_value (const GValue* value,
+                       guint n_collect_values,
+                       GTypeCValue* collect_values,
+                       guint collect_flags)
+{
+       Bar ** 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 = bar_ref (value->data[0].v_pointer);
+       }
+       return NULL;
+}
+
+GParamSpec*
+param_spec_bar (const gchar* name,
+                const gchar* nick,
+                const gchar* blurb,
+                GType object_type,
+                GParamFlags flags)
+{
+       ParamSpecBar* spec;
+       g_return_val_if_fail (g_type_is_a (object_type, TYPE_BAR), 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_bar (const GValue* value)
+{
+       g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_BAR), NULL);
+       return value->data[0].v_pointer;
+}
+
+void
+value_set_bar (GValue* value,
+               gpointer v_object)
+{
+       Bar * old;
+       g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_BAR));
+       old = value->data[0].v_pointer;
+       if (v_object) {
+               g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_BAR));
+               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;
+               bar_ref (value->data[0].v_pointer);
+       } else {
+               value->data[0].v_pointer = NULL;
+       }
+       if (old) {
+               bar_unref (old);
+       }
+}
+
+void
+value_take_bar (GValue* value,
+                gpointer v_object)
+{
+       Bar * old;
+       g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_BAR));
+       old = value->data[0].v_pointer;
+       if (v_object) {
+               g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_BAR));
+               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) {
+               bar_unref (old);
+       }
+}
+
+static void
+bar_class_init (BarClass * klass,
+                gpointer klass_data)
+{
+       bar_parent_class = g_type_class_peek_parent (klass);
+       ((BarClass *) klass)->finalize = bar_finalize;
+}
+
+static void
+bar_instance_init (Bar * self,
+                   gpointer klass)
+{
+       self->ref_count = 1;
+}
+
+static void
+bar_finalize (Bar * obj)
+{
+       Bar * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_BAR, Bar);
+       g_signal_handlers_destroy (self);
+}
+
+static GType
+bar_get_type_once (void)
+{
+       static const GTypeValueTable g_define_type_value_table = { value_bar_init, value_bar_free_value, 
value_bar_copy_value, value_bar_peek_pointer, "p", value_bar_collect_value, "p", value_bar_lcopy_value };
+       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, &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 bar_type_id;
+       bar_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Bar", &g_define_type_info, 
&g_define_type_fundamental_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;
+}
+
+gpointer
+bar_ref (gpointer instance)
+{
+       Bar * self;
+       self = instance;
+       g_atomic_int_inc (&self->ref_count);
+       return instance;
+}
+
+void
+bar_unref (gpointer instance)
+{
+       Bar * self;
+       self = instance;
+       if (g_atomic_int_dec_and_test (&self->ref_count)) {
+               BAR_GET_CLASS (self)->finalize (self);
+               g_type_free_instance ((GTypeInstance *) self);
+       }
+}
+
+static gboolean
+_foo_equal (const Foo * s1,
+            const Foo * s2)
+{
+       if (s1 == s2) {
+               return TRUE;
+       }
+       if (s1 == NULL) {
+               return FALSE;
+       }
+       if (s2 == NULL) {
+               return FALSE;
+       }
+       return (*s1) == (*s2);
+}
+
+static void
+_vala_main (void)
+{
+       Bar* bar = NULL;
+       Foo* _tmp1_;
+       Foo _tmp2_;
+       Foo* _tmp4_;
+       Foo _tmp5_;
+       {
+               Bar* _tmp0_;
+               _tmp0_ = bar_new (FOO);
+               _bar_unref0 (bar);
+               bar = _tmp0_;
+       }
+       _tmp1_ = bar->foo;
+       _tmp2_ = 23;
+       _vala_assert (_foo_equal (_tmp1_, &_tmp2_) == TRUE, "bar.foo == 23");
+       {
+               Foo _tmp3_;
+               _tmp3_ = FAZ;
+               bar->foo = &_tmp3_;
+       }
+       _tmp4_ = bar->foo;
+       _tmp5_ = 42;
+       _vala_assert (_foo_equal (_tmp4_, &_tmp5_) == TRUE, "bar.foo == 42");
+       _bar_unref0 (bar);
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/constants/member-access-enum.vala b/tests/constants/member-access-enum.vala
new file mode 100644
index 000000000..e0acb412f
--- /dev/null
+++ b/tests/constants/member-access-enum.vala
@@ -0,0 +1,27 @@
+enum Foo {
+       MANAM = 23,
+       MINIM = 42
+}
+
+const Foo FOO = Foo.MANAM;
+const Foo FAZ = Foo.MINIM;
+
+class Bar {
+       public unowned Foo? foo;
+
+       public Bar (Foo _foo) {
+               foo = _foo;
+       }
+}
+
+void main () {
+       Bar bar;
+       {
+               bar = new Bar (FOO);
+       }
+       assert (bar.foo == 23);
+       {
+               bar.foo = FAZ;
+       }
+       assert (bar.foo == 42);
+}
diff --git a/tests/enums/bug666035.c-expected b/tests/enums/bug666035.c-expected
index 558677334..07da7d02c 100644
--- a/tests/enums/bug666035.c-expected
+++ b/tests/enums/bug666035.c-expected
@@ -176,9 +176,7 @@ _vala_main (void)
        FooStruct foo_struct = {0};
        FooStruct _tmp4_ = {0};
        FooStruct _tmp5_;
-       FooEnum _tmp6_;
        FooEnum foo_enum = 0;
-       FooEnum _tmp7_;
        if (takes_enum (FOO_ENUM_BAR) == FOO_ENUM_BAR) {
                return;
        }
@@ -202,11 +200,9 @@ _vala_main (void)
        _tmp4_.f = FOO_ENUM_BAR;
        foo_struct = _tmp4_;
        _tmp5_ = foo_struct;
-       _tmp6_ = _tmp5_.f;
-       _vala_assert (_tmp6_ == FOO_ENUM_BAR, "foo_struct.f == BAR");
+       _vala_assert (_tmp5_.f == FOO_ENUM_BAR, "foo_struct.f == BAR");
        foo_enum = FOO_ENUM_BAR;
-       _tmp7_ = foo_enum;
-       switch (_tmp7_) {
+       switch (foo_enum) {
                default:
                case FOO_ENUM_FOO:
                {
diff --git a/tests/enums/enum-boxed.c-expected b/tests/enums/enum-boxed.c-expected
new file mode 100644
index 000000000..61def93cd
--- /dev/null
+++ b/tests/enums/enum-boxed.c-expected
@@ -0,0 +1,246 @@
+/* enums_enum_boxed.c generated by valac, the Vala compiler
+ * generated from enums_enum_boxed.vala, do not modify */
+
+#include <glib-object.h>
+#include <glib.h>
+#include <string.h>
+
+#define FOO FOO_BAR
+#define BAR BAR_FOO
+#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
+
+typedef enum  {
+       FOO_BAR = 23
+} Foo;
+
+#define TYPE_FOO (foo_get_type ())
+typedef enum  {
+       BAR_FOO = 42
+} Bar;
+
+#define TYPE_BAR (bar_get_type ())
+#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning 
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+
+VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
+VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
+static void _vala_main (void);
+static Foo* _foo_dup (Foo* self);
+static gboolean _foo_equal (const Foo * s1,
+                     const Foo * s2);
+static Bar* _bar_dup (Bar* self);
+static gboolean _bar_equal (const Bar * s1,
+                     const Bar * s2);
+
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_BAR, "FOO_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       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;
+}
+
+static GType
+bar_get_type_once (void)
+{
+       static const GFlagsValue values[] = {{BAR_FOO, "BAR_FOO", "foo"}, {0, NULL, NULL}};
+       GType bar_type_id;
+       bar_type_id = g_flags_register_static ("Bar", values);
+       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 Foo*
+_foo_dup (Foo* self)
+{
+       Foo* dup;
+       dup = g_new0 (Foo, 1);
+       memcpy (dup, self, sizeof (Foo));
+       return dup;
+}
+
+static gpointer
+__foo_dup0 (gpointer self)
+{
+       return self ? _foo_dup (self) : NULL;
+}
+
+static gboolean
+_foo_equal (const Foo * s1,
+            const Foo * s2)
+{
+       if (s1 == s2) {
+               return TRUE;
+       }
+       if (s1 == NULL) {
+               return FALSE;
+       }
+       if (s2 == NULL) {
+               return FALSE;
+       }
+       return (*s1) == (*s2);
+}
+
+static Bar*
+_bar_dup (Bar* self)
+{
+       Bar* dup;
+       dup = g_new0 (Bar, 1);
+       memcpy (dup, self, sizeof (Bar));
+       return dup;
+}
+
+static gpointer
+__bar_dup0 (gpointer self)
+{
+       return self ? _bar_dup (self) : NULL;
+}
+
+static gboolean
+_bar_equal (const Bar * s1,
+            const Bar * s2)
+{
+       if (s1 == s2) {
+               return TRUE;
+       }
+       if (s1 == NULL) {
+               return FALSE;
+       }
+       if (s2 == NULL) {
+               return FALSE;
+       }
+       return (*s1) == (*s2);
+}
+
+static void
+_vala_main (void)
+{
+       {
+               Foo* foo = NULL;
+               Foo _tmp0_;
+               Foo* _tmp1_;
+               Foo _tmp2_;
+               _tmp0_ = FOO_BAR;
+               _tmp1_ = __foo_dup0 (&_tmp0_);
+               foo = _tmp1_;
+               _tmp2_ = 23;
+               _vala_assert (_foo_equal (foo, &_tmp2_) == TRUE, "foo == 23");
+               _g_free0 (foo);
+       }
+       {
+               Foo* foo = NULL;
+               Foo _tmp3_;
+               Foo* _tmp4_;
+               Foo _tmp5_;
+               _tmp3_ = FOO;
+               _tmp4_ = __foo_dup0 (&_tmp3_);
+               foo = _tmp4_;
+               _tmp5_ = 23;
+               _vala_assert (_foo_equal (foo, &_tmp5_) == TRUE, "foo == 23");
+               _g_free0 (foo);
+       }
+       {
+               Foo* _tmp6_ = NULL;
+               Foo _tmp7_;
+               Foo* _tmp8_;
+               Foo* foo = NULL;
+               Foo* _tmp9_;
+               Foo _tmp10_;
+               _tmp7_ = FOO;
+               _tmp8_ = __foo_dup0 (&_tmp7_);
+               _tmp6_ = _tmp8_;
+               _tmp9_ = _tmp6_;
+               _tmp6_ = NULL;
+               foo = _tmp9_;
+               _tmp10_ = 23;
+               _vala_assert (_foo_equal (foo, &_tmp10_) == TRUE, "foo == 23");
+               _g_free0 (foo);
+               _g_free0 (_tmp6_);
+       }
+       {
+               Bar* bar = NULL;
+               Bar _tmp11_;
+               Bar* _tmp12_;
+               Bar _tmp13_;
+               _tmp11_ = BAR_FOO;
+               _tmp12_ = __bar_dup0 (&_tmp11_);
+               bar = _tmp12_;
+               _tmp13_ = 42;
+               _vala_assert (_bar_equal (bar, &_tmp13_) == TRUE, "bar == 42");
+               _g_free0 (bar);
+       }
+       {
+               Bar* bar = NULL;
+               Bar _tmp14_;
+               Bar* _tmp15_;
+               Bar _tmp16_;
+               _tmp14_ = BAR;
+               _tmp15_ = __bar_dup0 (&_tmp14_);
+               bar = _tmp15_;
+               _tmp16_ = 42;
+               _vala_assert (_bar_equal (bar, &_tmp16_) == TRUE, "bar == 42");
+               _g_free0 (bar);
+       }
+       {
+               Bar* _tmp17_ = NULL;
+               Bar _tmp18_;
+               Bar* _tmp19_;
+               Bar* bar = NULL;
+               Bar* _tmp20_;
+               Bar _tmp21_;
+               _tmp18_ = BAR;
+               _tmp19_ = __bar_dup0 (&_tmp18_);
+               _tmp17_ = _tmp19_;
+               _tmp20_ = _tmp17_;
+               _tmp17_ = NULL;
+               bar = _tmp20_;
+               _tmp21_ = 42;
+               _vala_assert (_bar_equal (bar, &_tmp21_) == TRUE, "bar == 42");
+               _g_free0 (bar);
+               _g_free0 (_tmp17_);
+       }
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/enums/enum-boxed.vala b/tests/enums/enum-boxed.vala
new file mode 100644
index 000000000..75c1ceaa6
--- /dev/null
+++ b/tests/enums/enum-boxed.vala
@@ -0,0 +1,39 @@
+enum Foo {
+       BAR = 23
+}
+
+const Foo FOO = Foo.BAR;
+
+[Flags]
+enum Bar {
+       FOO = 42
+}
+
+const Bar BAR = Bar.FOO;
+
+void main () {
+       {
+               Foo? foo = Foo.BAR;
+               assert (foo == 23);
+       }
+       {
+               Foo? foo = FOO;
+               assert (foo == 23);
+       }
+       {
+               var foo = (Foo?) FOO;
+               assert (foo == 23);
+       }
+       {
+               Bar? bar = Bar.FOO;
+               assert (bar == 42);
+       }
+       {
+               Bar? bar = BAR;
+               assert (bar == 42);
+       }
+       {
+               var bar = (Bar?) BAR;
+               assert (bar == 42);
+       }
+}
diff --git a/tests/objects/paramspec.c-expected b/tests/objects/paramspec.c-expected
index 70a32fa27..9185f79ee 100644
--- a/tests/objects/paramspec.c-expected
+++ b/tests/objects/paramspec.c-expected
@@ -552,10 +552,8 @@ FooEnum
 foo_get_enum_prop (Foo* self)
 {
        FooEnum result;
-       FooEnum _tmp0_;
        g_return_val_if_fail (IS_FOO (self), 0);
-       _tmp0_ = self->priv->_enum_prop;
-       result = _tmp0_;
+       result = self->priv->_enum_prop;
        return result;
 }
 
@@ -576,10 +574,8 @@ FooEnum
 foo_get_enum_prop2 (Foo* self)
 {
        FooEnum result;
-       FooEnum _tmp0_;
        g_return_val_if_fail (IS_FOO (self), 0);
-       _tmp0_ = self->priv->_enum_prop2;
-       result = _tmp0_;
+       result = self->priv->_enum_prop2;
        return result;
 }
 
@@ -600,10 +596,8 @@ FooFlag
 foo_get_flag_prop (Foo* self)
 {
        FooFlag result;
-       FooFlag _tmp0_;
        g_return_val_if_fail (IS_FOO (self), 0U);
-       _tmp0_ = self->priv->_flag_prop;
-       result = _tmp0_;
+       result = self->priv->_flag_prop;
        return result;
 }
 
@@ -624,10 +618,8 @@ FooFlag
 foo_get_flag_prop2 (Foo* self)
 {
        FooFlag result;
-       FooFlag _tmp0_;
        g_return_val_if_fail (IS_FOO (self), 0U);
-       _tmp0_ = self->priv->_flag_prop2;
-       result = _tmp0_;
+       result = self->priv->_flag_prop2;
        return result;
 }
 
diff --git a/tests/objects/property-enum.c-expected b/tests/objects/property-enum.c-expected
index 7c0570a66..50c02a146 100644
--- a/tests/objects/property-enum.c-expected
+++ b/tests/objects/property-enum.c-expected
@@ -244,10 +244,8 @@ FooEnum
 manam_get_prop1 (Manam* self)
 {
        FooEnum result;
-       FooEnum _tmp0_;
        g_return_val_if_fail (IS_MANAM (self), 0);
-       _tmp0_ = self->priv->_prop1;
-       result = _tmp0_;
+       result = self->priv->_prop1;
        return result;
 }
 
@@ -263,10 +261,8 @@ FooFlag
 manam_get_prop2 (Manam* self)
 {
        FooFlag result;
-       FooFlag _tmp0_;
        g_return_val_if_fail (IS_MANAM (self), 0U);
-       _tmp0_ = self->priv->_prop2;
-       result = _tmp0_;
+       result = self->priv->_prop2;
        return result;
 }
 
@@ -282,10 +278,8 @@ BarEnum
 manam_get_prop3 (Manam* self)
 {
        BarEnum result;
-       BarEnum _tmp0_;
        g_return_val_if_fail (IS_MANAM (self), 0);
-       _tmp0_ = self->priv->_prop3;
-       result = _tmp0_;
+       result = self->priv->_prop3;
        return result;
 }
 
@@ -301,10 +295,8 @@ BarFlag
 manam_get_prop4 (Manam* self)
 {
        BarFlag result;
-       BarFlag _tmp0_;
        g_return_val_if_fail (IS_MANAM (self), 0U);
-       _tmp0_ = self->priv->_prop4;
-       result = _tmp0_;
+       result = self->priv->_prop4;
        return result;
 }
 
@@ -542,10 +534,8 @@ FooEnum
 minim_get_prop1 (Minim* self)
 {
        FooEnum result;
-       FooEnum _tmp0_;
        g_return_val_if_fail (IS_MINIM (self), 0);
-       _tmp0_ = self->priv->_prop1;
-       result = _tmp0_;
+       result = self->priv->_prop1;
        return result;
 }
 
@@ -566,10 +556,8 @@ FooFlag
 minim_get_prop2 (Minim* self)
 {
        FooFlag result;
-       FooFlag _tmp0_;
        g_return_val_if_fail (IS_MINIM (self), 0U);
-       _tmp0_ = self->priv->_prop2;
-       result = _tmp0_;
+       result = self->priv->_prop2;
        return result;
 }
 
@@ -590,10 +578,8 @@ BarEnum
 minim_get_prop3 (Minim* self)
 {
        BarEnum result;
-       BarEnum _tmp0_;
        g_return_val_if_fail (IS_MINIM (self), 0);
-       _tmp0_ = self->priv->_prop3;
-       result = _tmp0_;
+       result = self->priv->_prop3;
        return result;
 }
 
@@ -614,10 +600,8 @@ BarFlag
 minim_get_prop4 (Minim* self)
 {
        BarFlag result;
-       BarFlag _tmp0_;
        g_return_val_if_fail (IS_MINIM (self), 0U);
-       _tmp0_ = self->priv->_prop4;
-       result = _tmp0_;
+       result = self->priv->_prop4;
        return result;
 }
 
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 3b93688e5..c43b913e9 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -473,6 +473,9 @@ public abstract class Vala.DataType : CodeNode {
                if (s != null && s.is_simple_type ()) {
                        return !nullable;
                }
+               if (type_symbol is Enum) {
+                       return !nullable;
+               }
                return false;
        }
 


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