]> 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 12:56:09 +0000 (14:56 +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 576e667f363387e59cf2be2b232c92323f3cd76a..54392247e44c7d31138562dd076112010f364f28 100644 (file)
@@ -155,6 +155,7 @@ TESTS = \
        enums/enum_only.vala \
        enums/enums.vala \
        enums/flags.vala \
+       enums/from-0-literal.vala \
        enums/bug673879.vala \
        enums/bug763831.vala \
        enums/bug780050.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;