]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Allow assignment of 0U to enum types 270361907182a4c8b4b291fd1a505d47dd8bcaae
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 10 Mar 2019 17:14:09 +0000 (18:14 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 10 Mar 2019 17:14:09 +0000 (18:14 +0100)
Don't restrict unsigned 0 literal to flags-enums though.

tests/Makefile.am
tests/enums/from-0-literal.vala [new file with mode: 0644]
vala/valaintegertype.vala

index c48c1a15b2754ce76776b787cfa8820f63630904..6c1653bda67f5c0bb153a81fe3dd2f2606e65f8e 100644 (file)
@@ -193,6 +193,7 @@ TESTS = \
        enums/enum-no-gtype.vala \
        enums/enums.vala \
        enums/flags.vala \
+       enums/from-0-literal.vala \
        enums/no_gtype_to_string.vala \
        enums/bug666035.vala \
        enums/bug666035-1.test \
diff --git a/tests/enums/from-0-literal.vala b/tests/enums/from-0-literal.vala
new file mode 100644 (file)
index 0000000..7f80258
--- /dev/null
@@ -0,0 +1,21 @@
+enum Foo {
+       BAR
+}
+
+[Flags]
+enum Bar {
+       FOO
+}
+
+void main () {
+       {
+               Foo foo;
+               foo = 0;
+               foo = 0U;
+       }
+       {
+               Bar bar;
+               bar = 0;
+               bar = 0U;
+       }
+}
index 53845455a478b280e99f7546cbf2872672ed7ab2..274fe4716d047e7c50f7d80bc15d54b8e1355743 100644 (file)
@@ -59,7 +59,7 @@ public class Vala.IntegerType : ValueType {
                                        return true;
                                }
                        }
-               } else if (target_type.data_type is Enum && literal_type_name == "int") {
+               } else if (target_type.data_type is Enum && (literal_type_name == "int" || literal_type_name == "uint")) {
                        // allow implicit conversion from 0 to enum and flags types
                        if (int.parse (literal_value) == 0) {
                                return true;