[vala/0.40] vala: Reject unary operations on nullable integer/floating and boolean type



commit 78772e92c35a9dea2db8449a11eb03e9d84844d8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 4 16:12:21 2019 +0200

    vala: Reject unary operations on nullable integer/floating and boolean type
    
    Prefer to report a semantic error rather than creating invalid c-code.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/772

 vala/valaunaryexpression.vala | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index 3adab0b2b..139881364 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -125,7 +125,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;
                }
 
@@ -134,7 +134,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;
                }
 
@@ -187,7 +187,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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]