[vala/0.48] vala: Non nullable enum types are simple types
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] vala: Non nullable enum types are simple types
- Date: Mon, 20 Dec 2021 19:00:30 +0000 (UTC)
commit c78ee27026288c2ba208fd0cda92316cfe3524c3
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 396565164..0087ad5f1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -101,6 +101,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 \
@@ -322,6 +323,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 b465fa0df..0385ea618 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -464,6 +464,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]