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



commit 4676a629a35c51455d114e152fb2c77a7fec8880
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.vala | 27 +++++++++++++++++++++++
 tests/enums/enum-boxed.vala             | 39 +++++++++++++++++++++++++++++++++
 vala/valadatatype.vala                  |  3 +++
 4 files changed, 71 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6da0d3cdf..8a92b7b0a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -102,6 +102,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 \
@@ -325,6 +326,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.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/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/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]