]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Infer needle type for "in" expression on enum
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 21 Feb 2021 09:40:25 +0000 (10:40 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 27 Feb 2021 19:26:43 +0000 (20:26 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1138

tests/Makefile.am
tests/enums/in-inference.vala [new file with mode: 0644]
vala/valabinaryexpression.vala

index dcac3682f020d6041fbbcb5c0581c158f1897521..54f23ef36ba0c4cc423d8993d37c12fdd85276b1 100644 (file)
@@ -309,6 +309,7 @@ TESTS = \
        enums/enums.vala \
        enums/flags.vala \
        enums/from-0-literal.vala \
+       enums/in-inference.vala \
        enums/no_gtype_to_string.vala \
        enums/switch.vala \
        enums/bug666035.vala \
diff --git a/tests/enums/in-inference.vala b/tests/enums/in-inference.vala
new file mode 100644 (file)
index 0000000..7f44df8
--- /dev/null
@@ -0,0 +1,14 @@
+[Flags]
+enum Foo {
+       FOO,
+       BAR,
+       MANAM;
+}
+
+void main () {
+       Foo foo = FOO | BAR;
+       if (MANAM in foo) {
+               assert_not_reached ();
+       }
+       assert (BAR in foo);
+}
index d632c5941d634c76af51d988935e37f1e3ec64d3..6b2ad57eba9a3d197a8fce2c194804c90aa9b4f1 100644 (file)
@@ -303,6 +303,11 @@ public class Vala.BinaryExpression : Expression {
                    && (operator == BinaryOperator.BITWISE_AND || operator == BinaryOperator.BITWISE_OR)) {
                        left.target_type = target_type.copy ();
                        right.target_type = target_type.copy ();
+               } else if (operator == BinaryOperator.IN) {
+                       right.check (context);
+                       if (right.value_type.type_symbol is Enum) {
+                               left.target_type = right.value_type.copy ();
+                       }
                }
                left.check (context);
                if (left.value_type != null && left.value_type.type_symbol is Enum