summaryrefslogtreecommitdiff
path: root/vala/valaunaryexpression.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-10-13 08:27:08 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2019-10-13 08:50:34 +0200
commit9792611445f48cdca4bc4c2d853f71f346e39ab7 (patch)
tree782a5ab7d884ef055c8b68bb4239a30c15ae684b /vala/valaunaryexpression.vala
parent9776597f710c407990523e0d9823e399c0d79f1a (diff)
downloadvala-9792611445f48cdca4bc4c2d853f71f346e39ab7.tar.gz
vala: Replace if-else-tree with switch in UnaryExpression.check()
Diffstat (limited to 'vala/valaunaryexpression.vala')
-rw-r--r--vala/valaunaryexpression.vala21
1 files changed, 14 insertions, 7 deletions
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index 4e2b50b90..0ab66ddef 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -166,7 +166,9 @@ public class Vala.UnaryExpression : Expression {
return false;
}
- if (operator == UnaryOperator.PLUS || operator == UnaryOperator.MINUS) {
+ switch (operator) {
+ case UnaryOperator.PLUS:
+ case UnaryOperator.MINUS:
// integer or floating point type
if (!is_numeric_type (inner.value_type)) {
error = true;
@@ -175,7 +177,8 @@ public class Vala.UnaryExpression : Expression {
}
value_type = inner.value_type;
- } else if (operator == UnaryOperator.LOGICAL_NEGATION) {
+ break;
+ case UnaryOperator.LOGICAL_NEGATION:
// boolean type
if (inner.value_type.nullable || !inner.value_type.compatible (context.analyzer.bool_type)) {
error = true;
@@ -184,7 +187,8 @@ public class Vala.UnaryExpression : Expression {
}
value_type = inner.value_type;
- } else if (operator == UnaryOperator.BITWISE_COMPLEMENT) {
+ break;
+ case UnaryOperator.BITWISE_COMPLEMENT:
// integer type
if (!is_integer_type (inner.value_type) && !(inner.value_type is EnumValueType)) {
error = true;
@@ -193,8 +197,9 @@ public class Vala.UnaryExpression : Expression {
}
value_type = inner.value_type;
- } else if (operator == UnaryOperator.INCREMENT ||
- operator == UnaryOperator.DECREMENT) {
+ break;
+ case UnaryOperator.INCREMENT:
+ case UnaryOperator.DECREMENT:
// integer type
if (!is_integer_type (inner.value_type)) {
error = true;
@@ -218,7 +223,8 @@ public class Vala.UnaryExpression : Expression {
parent_node.replace_expression (this, assignment);
assignment.check (context);
return true;
- } else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
+ case UnaryOperator.REF:
+ case UnaryOperator.OUT:
unowned ElementAccess? ea = inner as ElementAccess;
if (inner.symbol_reference is Field || inner.symbol_reference is Parameter || inner.symbol_reference is LocalVariable ||
(ea != null && ea.container.value_type is ArrayType)) {
@@ -230,7 +236,8 @@ public class Vala.UnaryExpression : Expression {
Report.error (source_reference, "ref and out method arguments can only be used with fields, parameters, local variables, and array element access");
return false;
}
- } else {
+ break;
+ default:
error = true;
Report.error (source_reference, "internal error: unsupported unary operator");
return false;