]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Non nullable enum types are simple types
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 16 Dec 2021 14:31:47 +0000 (15:31 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 20 Dec 2021 18:25:35 +0000 (19:25 +0100)
Fixes a regression of 5b6345a6386b05aaf3f11cb3572940413eb878a8

Fixes https://gitlab.gnome.org/GNOME/vala/issues/1268

tests/Makefile.am
tests/constants/member-access-enum.vala [new file with mode: 0644]
tests/enums/enum-boxed.vala [new file with mode: 0644]
vala/valadatatype.vala

index 6da0d3cdfe7ec33d8c41d61fc643f666bc150a02..8a92b7b0aea8e81ed1c16314ea279555ac933753 100644 (file)
@@ -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 (file)
index 0000000..e0acb41
--- /dev/null
@@ -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 (file)
index 0000000..75c1cea
--- /dev/null
@@ -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);
+       }
+}
index 3b93688e5322b0fa9f0cff2754c400a7d1291f67..c43b913e9d318c992e395fd319f9d7a7892e0c83 100644 (file)
@@ -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;
        }