summaryrefslogtreecommitdiff
path: root/vala/valaunaryexpression.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-09-04 16:12:21 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2019-09-04 16:12:21 +0200
commit5779d7f03e3db802e544d3b4c3b93d9142af6c7a (patch)
tree8822d6a639500d1d7a4f50fb733dec5f971a1cd9 /vala/valaunaryexpression.vala
parentd144372cfd690471ce9253fbff72de7b66015a72 (diff)
downloadvala-5779d7f03e3db802e544d3b4c3b93d9142af6c7a.tar.gz
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
Diffstat (limited to 'vala/valaunaryexpression.vala')
-rw-r--r--vala/valaunaryexpression.vala6
1 files changed, 3 insertions, 3 deletions
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index d371d39d9..c2ef3ab08 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -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;