]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Reject unary operations on nullable integer/floating and boolean type
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 4 Sep 2019 14:12:21 +0000 (16:12 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 4 Sep 2019 14:12:21 +0000 (16:12 +0200)
Prefer to report a semantic error rather than creating invalid c-code.

Fixes https://gitlab.gnome.org/GNOME/vala/issues/772

vala/valaunaryexpression.vala

index d371d39d926cb06fb3719c88502e865e45389b9d..c2ef3ab08d1a9987bf9f0f385aa4ef65f1913d66 100644 (file)
@@ -111,7 +111,7 @@ public class Vala.UnaryExpression : Expression {
        }
 
        bool is_numeric_type (DataType type) {
-               if (!(type.data_type is Struct)) {
+               if (type.nullable || !(type.data_type is Struct)) {
                        return false;
                }
 
@@ -120,7 +120,7 @@ public class Vala.UnaryExpression : Expression {
        }
 
        bool is_integer_type (DataType type) {
-               if (!(type.data_type is Struct)) {
+               if (type.nullable || !(type.data_type is Struct)) {
                        return false;
                }
 
@@ -177,7 +177,7 @@ public class Vala.UnaryExpression : Expression {
                        value_type = inner.value_type;
                } else if (operator == UnaryOperator.LOGICAL_NEGATION) {
                        // boolean type
-                       if (!inner.value_type.compatible (context.analyzer.bool_type)) {
+                       if (inner.value_type.nullable || !inner.value_type.compatible (context.analyzer.bool_type)) {
                                error = true;
                                Report.error (source_reference, "Operator not supported for `%s'".printf (inner.value_type.to_string ()));
                                return false;