[vala/staging] vala: Don't allow "in" operation with different enum types
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Don't allow "in" operation with different enum types
- Date: Sun, 21 Feb 2021 09:49:59 +0000 (UTC)
commit 3409c5ba24e2573c49113b21aef6c1a8ea28a484
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Feb 21 10:40:25 2021 +0100
vala: Don't allow "in" operation with different enum types
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1139
tests/Makefile.am | 1 +
tests/enums/in-invalid.test | 18 ++++++++++++++++++
vala/valabinaryexpression.vala | 5 +++++
3 files changed, 24 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c0e63b29c..860020161 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -311,6 +311,7 @@ TESTS = \
enums/flags.vala \
enums/from-0-literal.vala \
enums/in-inference.vala \
+ enums/in-invalid.test \
enums/no_gtype_to_string.vala \
enums/switch.vala \
enums/bug666035.vala \
diff --git a/tests/enums/in-invalid.test b/tests/enums/in-invalid.test
new file mode 100644
index 000000000..fb7ae4bf2
--- /dev/null
+++ b/tests/enums/in-invalid.test
@@ -0,0 +1,18 @@
+Invalid Code
+
+[Flags]
+enum Foo {
+ BAR,
+ MANAM;
+}
+
+[Flags]
+enum Bar {
+ MANAM,
+ FOO;
+}
+
+void main() {
+ Foo foo = MANAM;
+ assert (Bar.MANAM in foo);
+}
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 9fcefde30..d379927c0 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -573,6 +573,11 @@ public class Vala.BinaryExpression : Expression {
// integers or enums
left.target_type.nullable = false;
right.target_type.nullable = false;
+ if (left.value_type.type_symbol is Enum && right.value_type.type_symbol is
Enum
+ && left.value_type.type_symbol != right.value_type.type_symbol) {
+ error = true;
+ Report.error (source_reference, "Cannot look for `%s' in `%s'",
left.value_type.to_string (), right.value_type.to_string ());
+ }
} else if (right.value_type is ArrayType) {
if (!left.value_type.compatible (((ArrayType)
right.value_type).element_type)) {
error = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]