]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix comparison of nullable value types
authorSimon Werbeck <simon.werbeck@gmail.com>
Sun, 29 Jun 2014 15:00:37 +0000 (17:00 +0200)
committerLuca Bruno <luca.bruno@immobiliare.it>
Mon, 30 Jun 2014 13:40:56 +0000 (15:40 +0200)
Fixes bug 678791

tests/Makefile.am
tests/basic-types/bug678791.vala [new file with mode: 0644]
vala/valabinaryexpression.vala

index bcf82e1afaa0240295f88389f4c9fc4ceb5b78e8..07c98772d2279a3ad142dd81737dc4844292a78b 100644 (file)
@@ -34,6 +34,7 @@ TESTS = \
        basic-types/bug652380.vala \
        basic-types/bug655908.vala \
        basic-types/bug659975.vala \
+       basic-types/bug678791.vala \
        basic-types/bug686336.vala \
        namespaces.vala \
        methods/lambda.vala \
diff --git a/tests/basic-types/bug678791.vala b/tests/basic-types/bug678791.vala
new file mode 100644 (file)
index 0000000..2f3171f
--- /dev/null
@@ -0,0 +1,15 @@
+public enum Foo {
+       BAR
+}
+
+void main () {
+       int? a = null;
+       int b = 1;
+       assert (a != b);
+       assert (b != a);
+
+       Foo? f = null;
+       Foo g = Foo.BAR;
+       assert (f != g);
+       assert (g != f);
+}
index bdd9e5eb233cbf27bc0d89370a10880ab69e9cef..98b2e5eb64beefbb1d4eee4d991463e29437d5bc 100644 (file)
@@ -422,12 +422,12 @@ public class Vala.BinaryExpression : Expression {
                        right.target_type.value_owned = false;
 
                        if (left.value_type.nullable != right.value_type.nullable) {
-                               // if only one operand is nullable, make sure the other operand is promoted to nullable as well
-                               if (!left.value_type.nullable) {
-                                       left.target_type.nullable = true;
-                               } else if (!right.value_type.nullable) {
-                                       right.target_type.nullable = true;
-                               }
+                               // if only one operand is nullable, make sure the other
+                               // operand is promoted to nullable as well,
+                               // reassign both, as get_arithmetic_result_type doesn't
+                               // take nullability into account
+                               left.target_type.nullable = true;
+                               right.target_type.nullable = true;
                        }
 
                        value_type = context.analyzer.bool_type;