[vala/0.40] vala: Allow assignment of 0U to enum types
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] vala: Allow assignment of 0U to enum types
- Date: Tue, 9 Apr 2019 13:49:31 +0000 (UTC)
commit 5b56df181bd1c45216cdb1527e4e811ae8e0bec2
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Mar 10 18:14:09 2019 +0100
vala: Allow assignment of 0U to enum types
Don't restrict unsigned 0 literal to flags-enums though.
tests/Makefile.am | 1 +
tests/enums/from-0-literal.vala | 21 +++++++++++++++++++++
vala/valaintegertype.vala | 2 +-
3 files changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 629564a6d..9328a9f54 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -182,6 +182,7 @@ TESTS = \
enums/enum_only.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
index 000000000..7f802588d
--- /dev/null
+++ b/tests/enums/from-0-literal.vala
@@ -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;
+ }
+}
diff --git a/vala/valaintegertype.vala b/vala/valaintegertype.vala
index 53845455a..274fe4716 100644
--- a/vala/valaintegertype.vala
+++ b/vala/valaintegertype.vala
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]