]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Allow assignment of 0U to enum types
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 10 Mar 2019 17:14:09 +0000 (18:14 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 10 Apr 2019 14:26:19 +0000 (16:26 +0200)
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 cfe9b25a93256e0c9d26bae6c9d251cc3d9422b4..73c87a6b964821bc054422fa2674d9d40b7362f9 100644 (file)
@@ -189,6 +189,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/bug673879.vala \
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;